2018-09-17 00:27:00 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
2022-11-07 18:06:49 +00:00
|
|
|
# pylint: disable=pointless-statement, missing-docstring, invalid-name, pointless-string-statement
|
2020-05-20 15:29:39 +00:00
|
|
|
import json
|
2018-09-17 00:27:00 +00:00
|
|
|
import os
|
2021-03-22 14:26:26 +00:00
|
|
|
from pathlib import Path
|
2018-09-17 00:27:00 +00:00
|
|
|
|
|
|
|
import pytest
|
2022-01-06 01:12:46 +00:00
|
|
|
from pytest_mock import MockerFixture
|
2018-09-17 00:27:00 +00:00
|
|
|
|
2022-01-06 01:12:46 +00:00
|
|
|
from .. import api
|
|
|
|
from ..api import guessit, properties, suggested_expected, GuessitException, default_api
|
2018-09-17 00:27:00 +00:00
|
|
|
|
|
|
|
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
|
|
|
|
|
|
|
|
|
|
|
|
def test_default():
|
|
|
|
ret = guessit('Fear.and.Loathing.in.Las.Vegas.FRENCH.ENGLISH.720p.HDDVD.DTS.x264-ESiR.mkv')
|
|
|
|
assert ret and 'title' in ret
|
|
|
|
|
|
|
|
|
|
|
|
def test_forced_unicode():
|
2021-03-22 14:26:26 +00:00
|
|
|
ret = guessit('Fear.and.Loathing.in.Las.Vegas.FRENCH.ENGLISH.720p.HDDVD.DTS.x264-ESiR.mkv')
|
|
|
|
assert ret and 'title' in ret and isinstance(ret['title'], str)
|
2018-09-17 00:27:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_forced_binary():
|
|
|
|
ret = guessit(b'Fear.and.Loathing.in.Las.Vegas.FRENCH.ENGLISH.720p.HDDVD.DTS.x264-ESiR.mkv')
|
2021-03-22 14:26:26 +00:00
|
|
|
assert ret and 'title' in ret and isinstance(ret['title'], bytes)
|
2018-09-17 00:27:00 +00:00
|
|
|
|
|
|
|
|
2020-05-20 15:29:39 +00:00
|
|
|
def test_pathlike_object():
|
2021-03-22 14:26:26 +00:00
|
|
|
path = Path('Fear.and.Loathing.in.Las.Vegas.FRENCH.ENGLISH.720p.HDDVD.DTS.x264-ESiR.mkv')
|
|
|
|
ret = guessit(path)
|
|
|
|
assert ret and 'title' in ret
|
2020-05-20 15:29:39 +00:00
|
|
|
|
|
|
|
|
2018-09-17 00:27:00 +00:00
|
|
|
def test_unicode_japanese():
|
|
|
|
ret = guessit('[阿维达].Avida.2006.FRENCH.DVDRiP.XViD-PROD.avi')
|
|
|
|
assert ret and 'title' in ret
|
|
|
|
|
|
|
|
|
|
|
|
def test_unicode_japanese_options():
|
|
|
|
ret = guessit("[阿维达].Avida.2006.FRENCH.DVDRiP.XViD-PROD.avi", options={"expected_title": ["阿维达"]})
|
|
|
|
assert ret and 'title' in ret and ret['title'] == "阿维达"
|
|
|
|
|
|
|
|
|
|
|
|
def test_forced_unicode_japanese_options():
|
2021-03-22 14:26:26 +00:00
|
|
|
ret = guessit("[阿维达].Avida.2006.FRENCH.DVDRiP.XViD-PROD.avi", options={"expected_title": ["阿维达"]})
|
|
|
|
assert ret and 'title' in ret and ret['title'] == "阿维达"
|
2018-09-17 00:27:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_properties():
|
|
|
|
props = properties()
|
|
|
|
assert 'video_codec' in props.keys()
|
|
|
|
|
|
|
|
|
|
|
|
def test_exception():
|
|
|
|
with pytest.raises(GuessitException) as excinfo:
|
|
|
|
guessit(object())
|
2022-11-07 18:06:49 +00:00
|
|
|
assert "An internal error has occurred in guessit" in str(excinfo.value)
|
2018-09-17 00:27:00 +00:00
|
|
|
assert "Guessit Exception Report" in str(excinfo.value)
|
|
|
|
assert "Please report at https://github.com/guessit-io/guessit/issues" in str(excinfo.value)
|
2020-05-20 15:29:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_suggested_expected():
|
2022-01-06 01:12:46 +00:00
|
|
|
with open(os.path.join(__location__, 'suggested.json'), 'r', encoding='utf-8') as f:
|
2020-05-20 15:29:39 +00:00
|
|
|
content = json.load(f)
|
|
|
|
actual = suggested_expected(content['titles'])
|
|
|
|
assert actual == content['suggested']
|
2022-01-06 01:12:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_should_rebuild_rebulk_on_advanced_config_change(mocker: MockerFixture):
|
|
|
|
api.reset()
|
|
|
|
rebulk_builder_spy = mocker.spy(api, 'rebulk_builder')
|
|
|
|
|
|
|
|
string = "some.movie.trfr.mkv"
|
|
|
|
|
|
|
|
result1 = default_api.guessit(string)
|
|
|
|
|
|
|
|
assert result1.get('title') == 'some movie trfr'
|
|
|
|
assert 'subtitle_language' not in result1
|
|
|
|
|
|
|
|
rebulk_builder_spy.assert_called_once_with(mocker.ANY)
|
|
|
|
rebulk_builder_spy.reset_mock()
|
|
|
|
|
|
|
|
result2 = default_api.guessit(string, {'advanced_config': {'language': {'subtitle_prefixes': ['tr']}}})
|
|
|
|
|
|
|
|
assert result2.get('title') == 'some movie'
|
|
|
|
assert str(result2.get('subtitle_language')) == 'fr'
|
|
|
|
|
|
|
|
rebulk_builder_spy.assert_called_once_with(mocker.ANY)
|
|
|
|
rebulk_builder_spy.reset_mock()
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_not_rebuild_rebulk_on_same_advanced_config(mocker: MockerFixture):
|
|
|
|
api.reset()
|
|
|
|
rebulk_builder_spy = mocker.spy(api, 'rebulk_builder')
|
|
|
|
|
|
|
|
string = "some.movie.subfr.mkv"
|
|
|
|
|
|
|
|
result1 = default_api.guessit(string)
|
|
|
|
|
|
|
|
assert result1.get('title') == 'some movie'
|
|
|
|
assert str(result1.get('subtitle_language')) == 'fr'
|
|
|
|
|
|
|
|
rebulk_builder_spy.assert_called_once_with(mocker.ANY)
|
|
|
|
rebulk_builder_spy.reset_mock()
|
|
|
|
|
|
|
|
result2 = default_api.guessit(string)
|
|
|
|
|
|
|
|
assert result2.get('title') == 'some movie'
|
|
|
|
assert str(result2.get('subtitle_language')) == 'fr'
|
|
|
|
|
|
|
|
assert rebulk_builder_spy.call_count == 0
|
|
|
|
rebulk_builder_spy.reset_mock()
|