Exemplo n.º 1
0
def test_strict_argument(strict, exception, exp_exception, mocker):
    mocker.patch('upsies.utils.scene.assert_not_abbreviated_filename',
                 side_effect=exception)
    if exp_exception:
        exp_msg = re.escape(str(exp_exception))
        with pytest.raises(type(exp_exception), match=rf'^{exp_msg}$'):
            release.ReleaseInfo('foo.mkv', strict=strict)
    else:
        ri = release.ReleaseInfo('foo.mkv', strict=strict)
        assert ri['title'] == 'foo'
Exemplo n.º 2
0
def test_release_name_params(release_name, exp_params):
    for name, exp in ((release_name, exp_params),
                      (release_name.replace(' ',
                                            '.'), exp_params.replace(' ',
                                                                     '.'))):
        for path in (f'path/to/{name}.mkv', f'path/to/{name}/asdf.mkv'):
            print(repr(path), repr(exp))
            info = release.ReleaseInfo(path)
            assert info.release_name_params == exp
Exemplo n.º 3
0
def assert_info(release_name,
                type=ReleaseType.unknown,
                title='',
                aka='',
                country='',
                year='',
                episodes={},
                date='',
                edition=[],
                resolution='',
                service='',
                source='',
                audio_codec='',
                audio_channels='',
                video_codec='',
                group='',
                has_commentary=False):
    # Test space- and dot-separated release name
    for rn in (release_name, release_name.replace(' ', '.')):
        if '/' not in rn:
            # Test release name in file name and in parent directory name
            paths = (f'foo/{rn}.mkv', f'{rn}/foo.mkv')
        else:
            # Release name is already coming as path and grandparent directory
            # is not used for parsing
            paths = (f'foo/{rn}.mkv', )

        for path in paths:
            info = release.ReleaseInfo(path)
            assert info['type'] == type
            assert info['title'] == title
            assert info['aka'] == aka
            assert info['country'] == country
            assert info['year'] == year
            assert info['date'] == date
            assert info['episodes'] == episodes
            assert info['edition'] == edition
            assert info['resolution'] == resolution
            assert info['service'] == service
            assert info['source'] == source
            assert info['audio_codec'] == audio_codec
            assert info['audio_channels'] == audio_channels
            assert info['video_codec'] == video_codec
            assert info['group'] == group
            assert info['has_commentary'] == has_commentary
Exemplo n.º 4
0
def test_has_commentary(release_name, exp_value):
    expected = {
        'type': ReleaseType.movie,
        'title': 'The Foo',
        'year': '2000',
        'resolution': '1080p',
        'audio_codec': 'DTS',
        'video_codec': 'x264',
        'group': 'ASDF',
        'has_commentary': exp_value
    }
    assert_info(release_name, **expected)
    ri = release.ReleaseInfo(release_name)
    ri['has_commentary'] = ''
    assert ri['has_commentary'] is False
    ri['has_commentary'] = 1
    assert ri['has_commentary'] is True
    ri['has_commentary'] = None
    assert ri['has_commentary'] is exp_value
Exemplo n.º 5
0
def test_iter():
    ri = release.ReleaseInfo('foo.mkv')
    assert set(ri) == {
        'type',
        'title',
        'aka',
        'country',
        'date',
        'year',
        'episodes',
        'episode_title',
        'edition',
        'resolution',
        'service',
        'source',
        'audio_codec',
        'audio_channels',
        'video_codec',
        'group',
        'has_commentary',
    }
Exemplo n.º 6
0
def test_path():
    assert release.ReleaseInfo('path/to/foo').path == 'path/to/foo'
Exemplo n.º 7
0
def test_deleting_known_key():
    ri = release.ReleaseInfo('foo.mkv')
    assert ri['title'] == 'foo'
    del ri['title']
    assert ri['title'] == 'foo'
Exemplo n.º 8
0
def test_deleting_unknown_key():
    ri = release.ReleaseInfo('foo.mkv')
    with pytest.raises(KeyError, match=r"^'foo'$"):
        del ri['foo']
Exemplo n.º 9
0
def test_setting_unknown_key():
    ri = release.ReleaseInfo('foo.mkv')
    with pytest.raises(KeyError, match=r"^'foo'$"):
        ri['foo'] = 'bar'
    assert 'foo' not in ri
Exemplo n.º 10
0
def test_repr():
    ri = release.ReleaseInfo('path/to/foo.mkv')
    assert repr(ri) == "ReleaseInfo('path/to/foo.mkv')"
Exemplo n.º 11
0
def test_getting_known_key(mocker):
    ri = release.ReleaseInfo('foo.mkv')
    mocker.patch.object(ri, '_get_title', Mock(return_value='Mocked Title'))
    for _ in range(3):
        assert ri['title'] == 'Mocked Title'
    assert ri._get_title.call_args_list == [call()]
Exemplo n.º 12
0
def test_release_name_params_default():
    assert release.ReleaseInfo('path/to/Foo.mkv').release_name_params == 'Foo'
    assert release.ReleaseInfo('Foo.mkv').release_name_params == 'Foo'
    assert release.ReleaseInfo('Foo').release_name_params == 'Foo'
Exemplo n.º 13
0
def test_episodes_is_singleton():
    ri = release.ReleaseInfo('foo.mkv')
    episodes_id = id(ri['episodes'])
    ri['episodes'] = {1: (2, 3)}
    assert id(ri['episodes']) == episodes_id
Exemplo n.º 14
0
def test_len():
    ri = release.ReleaseInfo('foo.mkv')
    assert len(ri) == 17
Exemplo n.º 15
0
def test_setting_known_key():
    ri = release.ReleaseInfo('foo.mkv')
    assert ri['title'] == 'foo'
    ri['title'] = ''
    assert ri['title'] == ''
Exemplo n.º 16
0
def test_abbreviated_scene_filename(path, exp_release_name):
    ri = release.ReleaseInfo(path)
    release_name = '{title} {year} {resolution} {source} {video_codec}-{group}'.format(
        **ri)
    assert release_name == exp_release_name
Exemplo n.º 17
0
        async def search(self, *args, **kwargs):
            self.calls.append(call(*args, **kwargs))
            if exception:
                raise exception
            else:
                return f'{name} search results'

    return MockSceneDb()


@pytest.mark.parametrize(
    argnames='query, exp_query',
    argvalues=(
        ('path/to/release', find.SceneQuery.from_string('path/to/release')),
        (release.ReleaseInfo('release name'), find.SceneQuery.from_release(release.ReleaseInfo('release name'))),
        (('some', 'thing', 'else'), ('some', 'thing', 'else')),
    ),
)
@pytest.mark.asyncio
async def test_search_finds_query_results_directly(query, exp_query, mocker):
    mock_results = 'mock results'
    mock_dbs = ('mock db 1', 'mock db 2')
    mock_only_existing_releases = 'mock only existing releases'
    multisearch_mock = mocker.patch('upsies.utils.scene.find._multisearch', AsyncMock(return_value=mock_results))

    # find.search() is memoized (see utils.asyncmemoize)
    find.search.clear_cache()
    results = await find.search(query, mock_dbs, only_existing_releases=mock_only_existing_releases)
    assert results == mock_results
    assert multisearch_mock.call_args_list == [call(mock_dbs, exp_query, mock_only_existing_releases)]