Ejemplo n.º 1
0
def test_scan_videos_age(movies, tmpdir, monkeypatch):
    tmpdir.ensure('movies', movies['man_of_steel'].name)
    tmpdir.ensure('movies', movies['enders_game'].name).setmtime(
        timestamp(datetime.utcnow() - timedelta(days=10)))

    # mock scan_video and scan_archive with the correct types
    mock_video = Mock(subtitle_languages=set())
    mock_scan_video = Mock(return_value=mock_video)
    monkeypatch.setattr('subliminal.core.scan_video', mock_scan_video)
    mock_scan_archive = Mock(return_value=mock_video)
    monkeypatch.setattr('subliminal.core.scan_archive', mock_scan_archive)
    monkeypatch.chdir(str(tmpdir))
    videos = scan_videos('movies', age=timedelta(days=7))

    # general asserts
    assert len(videos) == 1
    assert mock_scan_video.call_count == 1
    assert mock_scan_archive.call_count == 0

    # scan_video calls
    kwargs = dict()
    scan_video_calls = [
        ((os.path.join('movies', movies['man_of_steel'].name), ), kwargs)
    ]
    mock_scan_video.assert_has_calls(scan_video_calls, any_order=True)
Ejemplo n.º 2
0
def test_scan_videos(movies, tmpdir, monkeypatch):
    man_of_steel = tmpdir.ensure('movies', movies['man_of_steel'].name)
    tmpdir.ensure('movies', '.private', 'sextape.mkv')
    tmpdir.ensure('movies', '.hidden_video.mkv')
    tmpdir.ensure('movies', movies['enders_game'].name)
    tmpdir.ensure('movies', movies['interstellar'].name)
    tmpdir.ensure('movies', os.path.splitext(movies['enders_game'].name)[0] + '.nfo')
    tmpdir.ensure('movies', 'watched', dir=True)
    tmpdir.join('movies', 'watched', os.path.split(movies['man_of_steel'].name)[1]).mksymlinkto(man_of_steel)

    # mock scan_video and scan_archive with the correct types
    mock_video = Mock(subtitle_languages=set())
    mock_scan_video = Mock(return_value=mock_video)
    monkeypatch.setattr('subliminal.core.scan_video', mock_scan_video)
    mock_scan_archive = Mock(return_value=mock_video)
    monkeypatch.setattr('subliminal.core.scan_archive', mock_scan_archive)
    monkeypatch.chdir(str(tmpdir))
    videos = scan_videos('movies')

    # general asserts
    assert len(videos) == 3
    assert mock_scan_video.call_count == 2
    assert mock_scan_archive.call_count == 1

    # scan_video calls
    kwargs = dict()
    scan_video_calls = [((os.path.join('movies', movies['man_of_steel'].name),), kwargs),
                        ((os.path.join('movies', movies['enders_game'].name),), kwargs)]
    mock_scan_video.assert_has_calls(scan_video_calls, any_order=True)

    # scan_archive calls
    kwargs = dict()
    scan_archive_calls = [((os.path.join('movies', movies['interstellar'].name),), kwargs)]
    mock_scan_archive.assert_has_calls(scan_archive_calls, any_order=True)
Ejemplo n.º 3
0
def test_scan_videos(movies, tmpdir, monkeypatch):
    man_of_steel = tmpdir.ensure('movies', movies['man_of_steel'].name)
    tmpdir.ensure('movies', '.private', 'sextape.mkv')
    tmpdir.ensure('movies', '.hidden_video.mkv')
    tmpdir.ensure('movies', 'Sample', 'video.mkv')
    tmpdir.ensure('movies', 'sample.mkv')
    tmpdir.ensure('movies', movies['enders_game'].name)
    tmpdir.ensure('movies', movies['interstellar'].name)
    tmpdir.ensure('movies',
                  os.path.splitext(movies['enders_game'].name)[0] + '.nfo')
    tmpdir.ensure('movies', 'watched', dir=True)
    watched_path = tmpdir.join('movies', 'watched',
                               os.path.split(movies['man_of_steel'].name)[1])
    if hasattr(watched_path, 'mksymlinkto'):
        watched_path.mksymlinkto(man_of_steel)

    # mock scan_video and scan_archive with the correct types
    mock_video = Mock(subtitle_languages=set())
    mock_scan_video = Mock(return_value=mock_video)
    monkeypatch.setattr('subliminal.core.scan_video', mock_scan_video)
    mock_scan_archive = Mock(return_value=mock_video)
    monkeypatch.setattr('subliminal.core.scan_archive', mock_scan_archive)
    monkeypatch.chdir(str(tmpdir))
    videos = scan_videos('movies')

    # general asserts
    assert len(videos) == 3
    assert mock_scan_video.call_count == 2
    assert mock_scan_archive.call_count == 1

    # scan_video calls
    kwargs = dict()
    scan_video_calls = [
        ((os.path.join('movies', movies['man_of_steel'].name), ), kwargs),
        ((os.path.join('movies', movies['enders_game'].name), ), kwargs)
    ]
    mock_scan_video.assert_has_calls(scan_video_calls, any_order=True)

    # scan_archive calls
    kwargs = dict()
    scan_archive_calls = [
        ((os.path.join('movies', movies['interstellar'].name), ), kwargs)
    ]
    mock_scan_archive.assert_has_calls(scan_archive_calls, any_order=True)
Ejemplo n.º 4
0
def test_scan_videos_age(movies, tmpdir, monkeypatch):
    tmpdir.ensure('movies', movies['man_of_steel'].name)
    tmpdir.ensure('movies', movies['enders_game'].name).setmtime(timestamp(datetime.utcnow() - timedelta(days=10)))

    # mock scan_video and scan_archive with the correct types
    mock_video = Mock(subtitle_languages=set())
    mock_scan_video = Mock(return_value=mock_video)
    monkeypatch.setattr('subliminal.core.scan_video', mock_scan_video)
    mock_scan_archive = Mock(return_value=mock_video)
    monkeypatch.setattr('subliminal.core.scan_archive', mock_scan_archive)
    monkeypatch.chdir(str(tmpdir))
    videos = scan_videos('movies', age=timedelta(days=7))

    # general asserts
    assert len(videos) == 1
    assert mock_scan_video.call_count == 1
    assert mock_scan_archive.call_count == 0

    # scan_video calls
    kwargs = dict()
    scan_video_calls = [((os.path.join('movies', movies['man_of_steel'].name),), kwargs)]
    mock_scan_video.assert_has_calls(scan_video_calls, any_order=True)
Ejemplo n.º 5
0
def test_scan_videos_path_is_not_a_directory(movies, tmpdir, monkeypatch):
    monkeypatch.chdir(str(tmpdir))
    tmpdir.ensure(movies['man_of_steel'].name)
    with pytest.raises(ValueError) as excinfo:
        scan_videos(movies['man_of_steel'].name)
    assert str(excinfo.value) == 'Path is not a directory'
Ejemplo n.º 6
0
def test_scan_videos_path_does_not_exist(movies):
    with pytest.raises(ValueError) as excinfo:
        scan_videos(movies['man_of_steel'].name)
    assert str(excinfo.value) == 'Path does not exist'
Ejemplo n.º 7
0
def test_scan_videos_path_is_not_a_directory(movies, tmpdir, monkeypatch):
    monkeypatch.chdir(str(tmpdir))
    tmpdir.ensure(movies['man_of_steel'].name)
    with pytest.raises(ValueError) as excinfo:
        scan_videos(movies['man_of_steel'].name)
    assert str(excinfo.value) == 'Path is not a directory'
Ejemplo n.º 8
0
def test_scan_videos_path_does_not_exist(movies):
    with pytest.raises(ValueError) as excinfo:
        scan_videos(movies['man_of_steel'].name)
    assert str(excinfo.value) == 'Path does not exist'