Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tnextday committed Sep 24, 2022
1 parent f381de8 commit 9d08df9
Showing 1 changed file with 52 additions and 30 deletions.
82 changes: 52 additions & 30 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

_test_dir = "_tests"
_app_path = "build/animenamer"
_tvdb_apikey = "Z5SC1ZD07NNS8TDC"

class MockFiles(unittest.TestCase):
def __init__(self, name, file_list):
Expand All @@ -34,13 +33,22 @@ def check_recovery(self, filepath):
def check_exists(self, filepath):
self.assertTrue(Path(self.base_dir.join(filepath)).exists())

_mock_files = [
"1-201/银魂.Gintama.003.mp4",
"1-201/银魂.Gintama.003.chs.ass",
"S2/银魂.Gintama.202.mkv",
"S2/银魂.Gintama.202.ass",
"S2/银魂.Gintama.203.ass",
"op/海贼王第10集.mkv",

]

class TestAnimeRenamer(unittest.TestCase):

def run_app(self, options, mock_fs, config=None, custom=None):
def run_app(self, options, base_dir, config=None, custom=None):

def write_config(cfg, name):
p = mock_fs.base_dir.joinpath(name)
p = base_dir.joinpath(name)
Path(p).write_text(json.dumps(cfg, indent=4))
return str(p)

Expand All @@ -54,60 +62,74 @@ def write_config(cfg, name):

cmds += []
cmds += options
cmds += [str(mock_fs.base_dir)]

try:
return subprocess.check_output(cmds, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
self.fail(e.output)

def test_anime_rename(self):
files = [
("1-201.BDRIP.720P.X264-10bit_AAC/银魂.Gintama.003.mp4","Gintama.S01E03.[003].mp4"),
("1-201.BDRIP.720P.X264-10bit_AAC/银魂.Gintama.003.chs.ass","Gintama.S01E03.[003].chs.ass"),
("银魂第二季.1080p.x264_AAC/银魂.Gintama.202.mkv", "Gintama.S05E01.[202].mkv"),
("银魂第二季.1080p.x264_AAC/银魂.Gintama.202.ass", "Gintama.S05E01.[202].ass"),
("银魂第二季.1080p.x264_AAC/银魂.Gintama.203.ass", "银魂.Gintama.203.ass"),
("op/海贼王第10集.mkv", "One Piece.S02E02.[010].mkv")
renamed_files = [
"Gintama.S01E03.[003].mp4",
"Gintama.S01E03.[003].chs.ass",
"Gintama.S05E01.[202].mkv",
"Gintama.S05E01.[202].ass",
"银魂.Gintama.203.ass",
"One Piece.S02E02.[010].mkv"
]
mock_fs = MockFiles("anime_ranme", [x[0] for x in files])
mock_fs = MockFiles("anime_ranme", _mock_files)
options = [
"--apikey", _tvdb_apikey,
"--language", "en",
"-p", r"银魂\.(?P<series>.+)\.(?P<absolute>\d+)\.(?P<ext>\w+?)$",
"-p", r"(?P<series>海贼王)第(?P<absolute>\d+)集\.(?P<ext>\w+?)$",
"--format", r"{series}.S{season.2}E{episode.2}.[{absolute.3}].{ext}",
str(mock_fs.base_dir)
]
o = self.run_app(options, mock_fs)
o = self.run_app(options, mock_fs.base_dir)
# print(o)
for r in files:
mock_fs.check_rename(r[0], r[1])
for i in range(0, len(_mock_files)):
mock_fs.check_rename(_mock_files[i], renamed_files[i])

def test_regexp_rename(self):
files = [
("1-201.BDRIP.720P.X264-10bit_AAC/银魂.Gintama.003.mp4","Gintama.[003].mp4"),
("1-201.BDRIP.720P.X264-10bit_AAC/银魂.Gintama.003.chs.ass","Gintama.[003].chs.ass"),
("银魂第二季.1080p.x264_AAC/银魂.Gintama.202.mkv", "Gintama.[202].mkv"),
("银魂第二季.1080p.x264_AAC/银魂.Gintama.202.ass", "Gintama.[202].ass"),
("银魂第二季.1080p.x264_AAC/银魂.Gintama.203.ass", "银魂.Gintama.203.ass"),
("op/海贼王第10集.mkv", "海贼王.[010].mkv")
renamed_files = [
"Gintama.[003].mp4",
"Gintama.[003].chs.ass",
"Gintama.[202].mkv",
"Gintama.[202].ass",
"银魂.Gintama.203.ass",
"海贼王.[010].mkv"
]
mock_fs = MockFiles("regexp_ranme", [x[0] for x in files])
mock_fs = MockFiles("regexp_ranme", _mock_files)
options = [
"-R",
"-p", r"银魂\.(?P<name>.+)\.(?P<absolute>\d+)\.\w+?$",
"-p", r"(?P<name>海贼王)第(?P<absolute>\d+)集\.\w+?$",
"--format", r"{name}.[{absolute.3}].{ext}",
str(mock_fs.base_dir)
]
o = self.run_app(options, mock_fs)
for r in files:
mock_fs.check_rename(r[0], r[1])
o = self.run_app(options, mock_fs.base_dir)
for i in range(0, len(_mock_files)):
mock_fs.check_rename(_mock_files[i], renamed_files[i])

def test_recovery(self):
pass

mock_fs = MockFiles("recovery_ranme", _mock_files)
rename_options = [
"-R",
"-p", r"银魂\.(?P<name>.+)\.(?P<absolute>\d+)\.\w+?$",
"-p", r"(?P<name>海贼王)第(?P<absolute>\d+)集\.\w+?$",
"--format", r"{name}.[{absolute.3}].{ext}",
str(mock_fs.base_dir)
]
o = self.run_app(rename_options, mock_fs.base_dir)
recovery_options = [
"recovery", mock_fs.base_dir.joinpath("rename.1.log")
]
o = self.run_app(recovery_options, mock_fs.base_dir)
for f in _mock_files:
mock_fs.check_recovery(f)

def setup(self):
print ("This is setUp")
print ("setUp")

def tearDown(self):
try:
Expand Down

0 comments on commit 9d08df9

Please sign in to comment.