Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Nov 9, 2024
1 parent d724a82 commit a993e0f
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 88 deletions.
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#
26 changes: 13 additions & 13 deletions tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import shutil
import subprocess
import tempfile
import typing
from typing import Optional

import musicbrainzngs
import musicbrainzngs.musicbrainz
Expand All @@ -18,12 +18,12 @@
from audiorename.args import ArgsDefault
from audiorename.musicbrainz import query, set_useragent

SKIP_API_CALLS = False
skip_api_calls = False
try:
set_useragent()
query("recording", "0480672d-4d88-4824-a06b-917ff408eabe")
except musicbrainzngs.musicbrainz.NetworkError:
SKIP_API_CALLS = True
skip_api_calls = True

SKIP_QUICK = "QUICK" in os.environ

Expand Down Expand Up @@ -60,9 +60,9 @@ def get_tmp_file_object(*path_list: str):


def gen_file_list(
files: typing.List[str], path: str, extension: str = "mp3"
) -> typing.List[str]:
output: typing.List[str] = []
files: list[str], path: str, extension: Optional[str] = "mp3"
) -> list[str]:
output: list[str] = []
for f in files:
if extension:
f = f + "." + extension
Expand All @@ -77,7 +77,7 @@ def get_job(**arguments: str) -> Job:
return Job(args)


def has(list: typing.List[str], search: str) -> bool:
def has(list: list[str], search: str) -> bool:
"""Check of a string is in list
:param list list: A list to search in.
Expand All @@ -94,11 +94,11 @@ def is_file(path: str) -> bool:
return os.path.isfile(path)


def join(output_list: typing.List[str]) -> str:
def join(output_list: list[str]) -> str:
return " ".join(output_list)


def dry_run(options: typing.List[str]) -> str:
def dry_run(options: list[str]) -> str:
"""Exectue the audiorename command in the ”dry” mode and capture the
output to get the renamed file path.
Expand All @@ -121,22 +121,22 @@ def dry_run(options: typing.List[str]) -> str:
return re.sub(r".* to: ", "", join(output)).strip()


def filter_source(output: typing.List[str]) -> typing.List[str]:
filtered: typing.List[str] = []
def filter_source(output: list[str]) -> list[str]:
filtered: list[str] = []
for line in output:
if line and line[0] == os.path.sep:
filtered.append(line)
return filtered


def call_bin(*args: str) -> typing.List[str]:
def call_bin(*args: str) -> list[str]:
args = ("audiorenamer",) + args
command = " ".join(args)
audiorename = subprocess.Popen(
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
audiorename.wait()
out: typing.List[str] = []
out: list[str] = []
if audiorename.stdout:
for line in audiorename.stdout.readlines():
out.append(line.decode("utf-8"))
Expand Down
14 changes: 7 additions & 7 deletions tests/test_all_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import datetime

import helper
from tests import helper

# from audiorename import args
# from phrydy import doc as pdoc
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_yesterday(self):
assert meta.albumartist_sort == "Beatles, The"
assert meta.albumdisambig is None
assert meta.albumstatus == "official"
assert meta.albumtype == "album/soundtrack"
assert meta.albumtype == "album"
assert meta.arranger is None
# self.assertEqual(meta.art, '')
assert meta.artist == "The Beatles"
Expand Down Expand Up @@ -143,7 +143,7 @@ def test_yesterday(self):
assert meta.encoder is None
assert meta.format == "MP3"
assert meta.genre is None
assert meta.genres == []
assert meta.genres is None
assert meta.grouping is None
# self.assertTrue(isinstance(meta.images[0],
# phrydy.mediafile_extended.Image))
Expand Down Expand Up @@ -173,7 +173,7 @@ def test_yesterday(self):
assert meta.rg_track_gain is None
assert meta.rg_track_peak is None
assert meta.samplerate == 24000
assert meta.ar_combined_soundtrack is True
assert meta.ar_combined_soundtrack is False
assert meta.script == "Latn"
assert meta.title == "Yesterday"
assert meta.ar_classical_title == "Yesterday"
Expand Down Expand Up @@ -247,7 +247,7 @@ def test_nachtmusik(self):
assert meta.encoder is None
assert meta.format == "MP3"
assert meta.genre is None
assert meta.genres == []
assert meta.genres is None
assert meta.grouping is None
# self.assertTrue(isinstance(meta.images[0], phrydy.mediafile.Image))
assert meta.initial_key is None
Expand Down Expand Up @@ -312,7 +312,7 @@ def test_wonderful(self):
assert meta.albumartist_sort == "Armstrong, Louis"
assert meta.albumdisambig is None
assert meta.albumstatus == "official"
assert meta.albumtype == "album/compilation"
assert meta.albumtype == "album"
assert meta.arranger is None
# self.assertEqual(meta.art, '')
assert meta.artist == "Louis Armstrong"
Expand Down Expand Up @@ -343,7 +343,7 @@ def test_wonderful(self):
assert meta.encoder is None
assert meta.format == "MP3"
assert meta.genre is None
assert meta.genres == []
assert meta.genres is None
assert meta.grouping is None
# self.assertTrue(isinstance(meta.images[0], phrydy.mediafile.Image))
assert meta.initial_key is None
Expand Down
2 changes: 1 addition & 1 deletion tests/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import re

import helper
import pytest

import audiorename
from tests import helper

with pytest.raises(ValueError) as exc_info:
raise ValueError("value must be 42")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_audiofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import shutil
import tempfile

import helper
import pytest

import audiorename
from audiorename import audiofile
from audiorename.meta import Meta
from tests import helper


class TestClassAction:
Expand All @@ -28,7 +28,7 @@ def test_method_delete(self) -> None:
helper.SKIP_QUICK, reason="Ignored, as it has to be done quickly."
)
@pytest.mark.skipif(
helper.SKIP_API_CALLS, reason="Ignored if the API is not available."
helper.skip_api_calls, reason="Ignored if the API is not available."
)
def test_method_metadata_enrich(self) -> None:
tmp = helper.get_tmp_file_object("classical", "without_work.mp3")
Expand Down
32 changes: 16 additions & 16 deletions tests/test_batch.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""Test the submodule “batchelper.py”."""

import helper

import audiorename
from tests import helper


class TestBatch:
Expand Down Expand Up @@ -47,24 +46,25 @@ def setup_method(self) -> None:

def test_single(self) -> None:
single = helper.get_testfile("files", "album.mp3")
with helper.Capturing() as output:
with helper.Capturing(clean_ansi=True) as output:
audiorename.execute("--dry-run", "--verbose", single)

assert [single] == helper.filter_source(output)

def test_folder_complete(self) -> None:
with helper.Capturing() as output:
with helper.Capturing(clean_ansi=True) as output:
audiorename.execute("--dry-run", "--verbose", helper.get_testfile("files"))
assert self.all == helper.filter_source(output)

def test_folder_sub(self) -> None:
with helper.Capturing() as output:
with helper.Capturing(clean_ansi=True) as output:
audiorename.execute(
"--dry-run", "--verbose", helper.get_testfile("files", "album_complete")
)
assert self.album_complete == helper.filter_source(output)

def test_album_min(self) -> None:
with helper.Capturing() as output:
with helper.Capturing(clean_ansi=True) as output:
audiorename.execute(
"--dry-run",
"--verbose",
Expand All @@ -77,7 +77,7 @@ def test_album_min(self) -> None:
)

def test_album_min_no_match(self) -> None:
with helper.Capturing() as output:
with helper.Capturing(clean_ansi=True) as output:
audiorename.execute(
"--dry-run",
"--verbose",
Expand All @@ -88,7 +88,7 @@ def test_album_min_no_match(self) -> None:
assert [] == helper.filter_source(output)

def test_album_complete(self) -> None:
with helper.Capturing() as output:
with helper.Capturing(clean_ansi=True) as output:
audiorename.execute(
"--dry-run",
"--verbose",
Expand All @@ -101,7 +101,7 @@ def test_album_complete(self) -> None:
)

def test_filter_all(self) -> None:
with helper.Capturing() as output:
with helper.Capturing(clean_ansi=True) as output:
audiorename.execute(
"--dry-run",
"--verbose",
Expand All @@ -118,32 +118,32 @@ def setup_method(self) -> None:
self.test_files = helper.get_testfile("mixed_formats")

def test_default(self) -> None:
with helper.Capturing() as output:
with helper.Capturing(clean_ansi=True) as output:
audiorename.execute(
"--dry-run",
"--verbose",
self.test_files,
)
assert helper.filter_source(output) == helper.gen_file_list(
["01.flac", "02.m4a", "03.mp3"], self.test_files, extension=False
["01.flac", "02.m4a", "03.mp3"], self.test_files, extension=None
)

def test_one(self) -> None:
with helper.Capturing() as output:
with helper.Capturing(clean_ansi=True) as output:
audiorename.execute(
"--dry-run", "--verbose", "--extension", "mp3,flac", self.test_files
)
assert helper.filter_source(output) == helper.gen_file_list(
["01.flac", "03.mp3"], self.test_files, extension=False
["01.flac", "03.mp3"], self.test_files, extension=None
)

def test_two(self) -> None:
with helper.Capturing() as output:
with helper.Capturing(clean_ansi=True) as output:
audiorename.execute(
"--dry-run", "--verbose", "--extension", "mp3", self.test_files
)
assert helper.filter_source(output) == helper.gen_file_list(
["03.mp3"], self.test_files, extension=False
["03.mp3"], self.test_files, extension=None
)


Expand All @@ -163,7 +163,7 @@ def test_file_in_message(self) -> None:

def test_continuation(self) -> None:
path = helper.get_testfile("broken")
with helper.Capturing() as output:
with helper.Capturing(clean_ansi=True) as output:
audiorename.execute("--dry-run", "--verbose", path)
output = helper.filter_source(output)
assert output[1]
4 changes: 2 additions & 2 deletions tests/test_cli_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import shutil
import tempfile

import helper
import pytest

import audiorename
from tests import helper


# --best-format
Expand Down Expand Up @@ -397,7 +397,7 @@ class TestEnrichMetadata:
helper.SKIP_QUICK, reason="Ignored, as it has to be done quickly."
)
@pytest.mark.skipif(
helper.SKIP_API_CALLS, reason="Ignored if the API is not available."
helper.skip_api_calls, reason="Ignored if the API is not available."
)
def test_pass(self) -> None:
tmp = helper.copy_to_tmp("classical", "without_work.mp3")
Expand Down
3 changes: 1 addition & 2 deletions tests/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import os
import typing

import helper

from audiorename.args import ArgsDefault
from audiorename.job import Counter, Job, Timer
from tests import helper


def job(**kwargs: typing.Any) -> Job:
Expand Down
3 changes: 1 addition & 2 deletions tests/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

from typing import Any

import helper

from audiorename import audiofile
from audiorename.message import Message
from tests import helper


class TestClassMessage:
Expand Down
Loading

0 comments on commit a993e0f

Please sign in to comment.