Add tests
This commit is contained in:
parent
1b3af219d2
commit
58b1606a62
@ -23,6 +23,7 @@ PATTERNS = (
|
||||
("edition", r"((theatrical|director'*s|extended|un)[-.]?cut"
|
||||
r"|imax[-.]edition"
|
||||
r"|noir[-.]edition"
|
||||
r"|black[-.]chrome[-.]edition"
|
||||
r"|extended[-.]edition"
|
||||
r"|theatrical)"),
|
||||
("restrictions", r"(unrated)"),
|
||||
|
||||
@ -1 +1,3 @@
|
||||
black
|
||||
pylint
|
||||
pytest
|
||||
|
||||
194
tests/test_parsing.py
Normal file
194
tests/test_parsing.py
Normal file
@ -0,0 +1,194 @@
|
||||
import unittest
|
||||
from renamer import parse_title
|
||||
|
||||
|
||||
class TestParser(unittest.TestCase):
|
||||
def test_misc_separators(self):
|
||||
title = "V tumane 2012 1080p BluRay DD5.1 x264-EA"
|
||||
res = parse_title(title)
|
||||
self.assertIn("DD5.1", res.get("audio", []))
|
||||
self.assertIn("x264", res.get("codec", []))
|
||||
self.assertIn("EA", res.get("unknown", []))
|
||||
self.assertEqual(
|
||||
res,
|
||||
{
|
||||
"year": ["2012"],
|
||||
"resolution": ["1080p"],
|
||||
"quality": ["BluRay"],
|
||||
"audio": ["DD5.1"],
|
||||
"codec": ["x264"],
|
||||
"name": ["V", "tumane"],
|
||||
"unknown": ["EA"],
|
||||
},
|
||||
)
|
||||
|
||||
@unittest.expectedFailure
|
||||
def test_russian_char_in_resolution(self):
|
||||
title = "Trouble.with.the.Curve.2012.1080р.BluRay.Rus.Eng.HDCLUB"
|
||||
res = parse_title(title)
|
||||
self.assertIn("1080p", res.get("resolution", []))
|
||||
self.assertEqual(
|
||||
res,
|
||||
{
|
||||
"year": ["2012"],
|
||||
"quality": ["BluRay"],
|
||||
"language": ["Rus", "Eng"],
|
||||
"resolution": ["1080p"],
|
||||
"name": ["Trouble", "with", "the", "Curve"],
|
||||
"unknown": ["HDCLUB"],
|
||||
},
|
||||
)
|
||||
|
||||
def test_russian_name(self):
|
||||
title = "Убийство (1956. The Killing)"
|
||||
res = parse_title(title)
|
||||
self.assertEqual(
|
||||
res,
|
||||
{
|
||||
"year": ["1956"],
|
||||
"name": ["Убийство"],
|
||||
"unknown": ["The", "Killing"],
|
||||
},
|
||||
)
|
||||
|
||||
def test_only_name_goes_to_unknown(self):
|
||||
title = "Белое солнце пустыни"
|
||||
res = parse_title(title)
|
||||
self.assertEqual(res, {"unknown": ["Белое", "солнце", "пустыни"]})
|
||||
|
||||
def test_hyphen_as_separated_chunk(self):
|
||||
title = "Miss Pettigrew Lives for a Day. 2007. BDRip (1080p) - ylnian"
|
||||
self.assertEqual(
|
||||
parse_title(title),
|
||||
{
|
||||
"year": ["2007"],
|
||||
"quality": ["BDRip"],
|
||||
"resolution": ["1080p"],
|
||||
"name": ["Miss", "Pettigrew", "Lives", "for", "a", "Day"],
|
||||
"unknown": ["ylnian"],
|
||||
},
|
||||
)
|
||||
|
||||
def test_file_extension_goes_to_unknown(self):
|
||||
title = "Monsters,Inc.2001.BDRip.1080p.3xRus.Ukr.Eng.HDCLUB.mkv"
|
||||
res = parse_title(title)
|
||||
self.assertIn("mkv", res.get("unknown", []))
|
||||
self.assertEqual(
|
||||
res,
|
||||
{
|
||||
"year": ["2001"],
|
||||
"quality": ["BDRip"],
|
||||
"resolution": ["1080p"],
|
||||
"language": ["3xRus", "Ukr", "Eng"],
|
||||
"name": ["Monsters", "Inc"],
|
||||
"unknown": ["HDCLUB", "mkv"],
|
||||
},
|
||||
)
|
||||
|
||||
def test_edition_after_name(self):
|
||||
title = "Logan.2017.noir.edition.BDRip.1080p.HEVC"
|
||||
res = parse_title(title)
|
||||
self.assertIn("noir.edition", res.get("edition", []))
|
||||
self.assertIn("Logan", res.get("name", []))
|
||||
self.assertEqual(
|
||||
res,
|
||||
{
|
||||
"year": ["2017"],
|
||||
"quality": ["BDRip"],
|
||||
"resolution": ["1080p"],
|
||||
"codec": ["HEVC"],
|
||||
"edition": ["noir.edition"],
|
||||
"name": ["Logan"],
|
||||
},
|
||||
)
|
||||
|
||||
@unittest.expectedFailure
|
||||
def test_chunk_from_three_parts(self):
|
||||
title = "Mad.Max.Road.of.Fury.Black.Chrome.edition.BDRip.1080p"
|
||||
self.assertEqual(
|
||||
parse_title(title),
|
||||
{
|
||||
"quality": ["BDRip"],
|
||||
"resolution": ["1080p"],
|
||||
"edition": ["Black.Chrome.edition"],
|
||||
"name": ["Mad", "Max", "Road", "of", "Fury"],
|
||||
},
|
||||
)
|
||||
|
||||
@unittest.expectedFailure
|
||||
def test_ampersand_in_title(self):
|
||||
title = "Me.Myself.&.Irene.2000.720p.BluRay.4xRus.Ukr.Eng"
|
||||
res = parse_title(title)
|
||||
self.assertIn("&", res.get("name", []))
|
||||
self.assertEqual(
|
||||
res,
|
||||
{
|
||||
"year": ["2000"],
|
||||
"resolution": ["720p"],
|
||||
"quality": ["BluRay"],
|
||||
"language": ["4xRus", "Ukr", "Eng"],
|
||||
"name": ["Me", "Myself", "&", "Irene"],
|
||||
},
|
||||
)
|
||||
|
||||
def test_brackets_and_parenthesis(self):
|
||||
title = "Leon.(1994).BDRip.1080p.(DVD9).[NoLimits-Team]"
|
||||
res = parse_title(title)
|
||||
self.assertEqual(
|
||||
res,
|
||||
{
|
||||
"year": ["1994"],
|
||||
"quality": ["BDRip", "DVD9"],
|
||||
"resolution": ["1080p"],
|
||||
"name": ["Leon"],
|
||||
"unknown": ["NoLimits-Team"],
|
||||
},
|
||||
)
|
||||
|
||||
def test_multiple_languages(self):
|
||||
title = "The.Theory.of.Everything.2014.720p.BluRay.2xRus.2xEng.HDCLUB"
|
||||
res = parse_title(title)
|
||||
self.assertIn("2xRus", res.get("language", []))
|
||||
self.assertIn("2xEng", res.get("language", []))
|
||||
self.assertEqual(
|
||||
res,
|
||||
{
|
||||
"year": ["2014"],
|
||||
"resolution": ["720p"],
|
||||
"quality": ["BluRay"],
|
||||
"language": ["2xRus", "2xEng"],
|
||||
"name": ["The", "Theory", "of", "Everything"],
|
||||
"unknown": ["HDCLUB"],
|
||||
},
|
||||
)
|
||||
|
||||
def test_subtitles(self):
|
||||
title = "Lives.of.Others.Blu-RayRip.720p.RusDTS.GerAC3.EngSub"
|
||||
res = parse_title(title)
|
||||
self.assertIn("EngSub", res.get("subtitles", []))
|
||||
self.assertEqual(
|
||||
res,
|
||||
{
|
||||
"quality": ["Blu-RayRip"],
|
||||
"resolution": ["720p"],
|
||||
"audio": ["RusDTS", "GerAC3"],
|
||||
"subtitles": ["EngSub"],
|
||||
"name": ["Lives", "of", "Others"],
|
||||
},
|
||||
)
|
||||
|
||||
def test_strange_dot_in_name(self):
|
||||
title = "WALL·E.2008.1080p.BluRay.3xRus.Ukr.Eng.HDCLUB-Skazhutin"
|
||||
res = parse_title(title)
|
||||
self.assertIn("WALL·E", res.get("name", []))
|
||||
self.assertEqual(
|
||||
res,
|
||||
{
|
||||
"year": ["2008"],
|
||||
"resolution": ["1080p"],
|
||||
"quality": ["BluRay"],
|
||||
"language": ["3xRus", "Ukr", "Eng"],
|
||||
"name": ["WALL·E"],
|
||||
"unknown": ["HDCLUB-Skazhutin"],
|
||||
},
|
||||
)
|
||||
Loading…
Reference in New Issue
Block a user