def testFailSecondStubSameMethodUnused(self):
     when(Dog).bark('Miau')
     when(Dog).bark('Grrr')
     rex = Dog()
     rex.bark('Miau')
     with pytest.raises(VerificationError):
         verifyStubbedInvocationsAreUsed(Dog)
Beispiel #2
0
 def testPassTwoStubsOnSameMethodUsed(self):
     when(Dog).bark('Miau')
     when(Dog).bark('Grrr')
     rex = Dog()
     rex.bark('Miau')
     rex.bark('Grrr')
     verifyStubbedInvocationsAreUsed(Dog)
Beispiel #3
0
 def testPassOneCatchAllOneSpecificStubBothUsed(self):
     when(Dog).bark(Ellipsis)
     when(Dog).bark('Miau')
     rex = Dog()
     rex.bark('Miau')
     rex.bark('Grrr')
     verifyStubbedInvocationsAreUsed(Dog)
 def testPassOneCatchAllOneSpecificStubBothUsed(self):
     when(Dog).bark(Ellipsis)
     when(Dog).bark('Miau')
     rex = Dog()
     rex.bark('Miau')
     rex.bark('Grrr')
     verifyStubbedInvocationsAreUsed(Dog)
Beispiel #5
0
        def testPassIfExplicitlyVerified4(self):
            dog = mock()
            when(dog).waggle(1).thenReturn('Sure')
            when(dog).waggle(2).thenReturn('Sure')
            verify(dog, times=0).waggle(Ellipsis)

            verifyStubbedInvocationsAreUsed(dog)
Beispiel #6
0
def test_missing_queue():
    not_the_main_process = mock()
    not_the_main_process.name = 'not_the_main_process'
    when(multiprocessing).current_process().thenReturn(not_the_main_process)
    with pytest.raises(elib_logging.exc.MissingQueueError):
        elib_logging.get_logger()
    verifyStubbedInvocationsAreUsed()
def test_update_mod_id_after_download(mock_repo):
    download = Download(mock_repo)

    mod_arg = Mod("dummy", "name")
    installed_mod = Mod("validid", "name", version="1.0.0")
    expected_mod = Mod(
        "validid",
        "name",
        sites={Sites.curse: Site(Sites.curse, "", "")},
        version="1.0.0",
        file="mod.jar",
    )
    version_info = VersionInfo(
        stability=Stabilities.release,
        mod_loaders={ModLoaders.fabric},
        site=Sites.curse,
        upload_time=0,
        minecraft_versions=[],
        download_url="",
    )
    when(mock_repo).search_for_mod(...).thenReturn(
        {Sites.curse: Site(Sites.curse, "", "")})
    when(mock_repo).get_versions(...).thenReturn([version_info])
    when(mock_repo).download(...).thenReturn(Path("mod.jar"))
    when(mock_repo).update_mod(expected_mod)
    when(mock_repo).get_mod_from_file("mod.jar").thenReturn(installed_mod)
    when(download).on_version_found(...)

    download.find_download_and_install([mod_arg])

    verifyStubbedInvocationsAreUsed()
    unstub()
 def testFailSecondStubNotUsed(self):
     when(Dog).bark('Miau')
     when(Dog).waggle()
     rex = Dog()
     rex.bark('Miau')
     with pytest.raises(VerificationError):
         verifyStubbedInvocationsAreUsed(Dog)
Beispiel #9
0
 def testFailSecondStubSameMethodUnused(self):
     when(Dog).bark('Miau')
     when(Dog).bark('Grrr')
     rex = Dog()
     rex.bark('Miau')
     with pytest.raises(VerificationError):
         verifyStubbedInvocationsAreUsed(Dog)
Beispiel #10
0
 def testFailSecondStubNotUsed(self):
     when(Dog).bark('Miau')
     when(Dog).waggle()
     rex = Dog()
     rex.bark('Miau')
     with pytest.raises(VerificationError):
         verifyStubbedInvocationsAreUsed(Dog)
        def testPassIfExplicitlyVerified4(self):
            dog = mock()
            when(dog).waggle(1).thenReturn('Sure')
            when(dog).waggle(2).thenReturn('Sure')
            verify(dog, times=0).waggle(Ellipsis)

            verifyStubbedInvocationsAreUsed(dog)
 def testPassTwoStubsOnSameMethodUsed(self):
     when(Dog).bark('Miau')
     when(Dog).bark('Grrr')
     rex = Dog()
     rex.bark('Miau')
     rex.bark('Grrr')
     verifyStubbedInvocationsAreUsed(Dog)
def test_call_find_download_and_install(mock_repo):
    install = Install(mock_repo)
    when(mock_repo).get_all_mods(...).thenReturn([])
    when(install).find_download_and_install(...)
    install.execute([])

    verifyStubbedInvocationsAreUsed()
    unstub()
Beispiel #14
0
def test_call():
    when(elib).run('test some command', mute=True).thenReturn(('out', None))
    sub = Sub()
    exe = mock()
    when(exe).absolute().thenReturn('test')
    sub._exe = exe
    assert sub('some command') == 'out'
    verifyStubbedInvocationsAreUsed()
Beispiel #15
0
def test_pandoc():
    pandoc = external_tools.Pandoc()
    exe = Path('exe')
    when(pandoc).get_exe().thenReturn(exe)
    when(elib).run(contains('--version'), mute=True).thenReturn(
        ('pandoc version\ntext', 0))
    assert pandoc.get_version() == 'version'
    assert pandoc.get_version() == 'version'
    verifyStubbedInvocationsAreUsed()
Beispiel #16
0
def test_process_finished(dummy_kwargs):
    command = mock()
    when(command).poll().thenReturn(None).thenReturn(0)
    context = _run_context.RunContext(**dummy_kwargs)
    setattr(context, '_command', command)
    assert not context.process_finished()
    assert context.process_finished()
    verifyNoUnwantedInteractions()
    verifyStubbedInvocationsAreUsed()
Beispiel #17
0
def test_call_find_download_and_install(mock_repo):
    when(mock_repo).get_all_mods().thenReturn([])
    update = Update(mock_repo)
    when(update).find_download_and_install(...)

    update.execute([])

    verifyStubbedInvocationsAreUsed()
    unstub()
Beispiel #18
0
def test_capture_simple(caplog):
    caplog.set_level(10, 'elib_run.process')
    context = _dummy_context()
    when(context.capture).readline(block=False).thenReturn(b'random string').thenReturn(None)
    _capture_output.capture_output_from_running_process(context)
    verifyNoUnwantedInteractions()
    verifyStubbedInvocationsAreUsed()
    assert ['random string'] == context.process_output_chunks
    assert 'random string' in caplog.text
def test_find_mod_id_by_slug(name, mod: Mod, expected, api: ModrinthApi, search_result):
    print(name)
    when(api.downloader).get(...).thenReturn(search_result)

    result = api._find_mod_id_by_slug("", mod.get_possible_slugs())

    verifyStubbedInvocationsAreUsed()
    unstub()

    assert expected == result
def test_configure_mod(name: str, existing: Mod, input: List[ModArg],
                       expected: Mod, mock_repo: ConfigureRepo):
    when(mock_repo).get_mod(existing.id).thenReturn(existing)
    when(mock_repo).update_mod(expected)

    configure = Configure(mock_repo)
    configure.execute(input)

    verifyStubbedInvocationsAreUsed()
    unstub()
Beispiel #21
0
def test_use_all_installed_mods_when_no_mods_are_specified(mock_repo):
    mods: List[Mod] = [Mod("1", "one"), Mod("2", "two")]
    update = Update(mock_repo)
    when(mock_repo).get_all_mods().thenReturn(mods)
    when(update).find_download_and_install(...)

    update.execute([])

    verifyStubbedInvocationsAreUsed()
    unstub()
Beispiel #22
0
def test_capture_muted():
    context = _dummy_context()
    context.mute = True
    when(context.capture).readline(block=False).thenReturn(b'random string').thenReturn(None)
    when(context.process_logger).debug(...)
    _capture_output.capture_output_from_running_process(context)
    verify(context.process_logger, times=0).debug(...)
    verifyNoUnwantedInteractions()
    verifyStubbedInvocationsAreUsed()
    assert ['random string'] == context.process_output_chunks
def test_mod_not_installed_when_already_installed(mock_repo):
    when(mock_repo).is_installed(...).thenReturn(True)
    when(mock_repo).get_all_mods(...).thenReturn([])

    input = [ModArg("")]
    install = Install(mock_repo)
    install.execute(input)

    verifyStubbedInvocationsAreUsed()
    unstub()
def test_build_folder_skip():
    ctx, _ = _get_standard_build_folder()
    ctx.settings.papersize = ['a4']
    when(_make_pdf).get_media_folders(...)
    when(_make_pdf).skip_file(...).thenReturn(True)
    when(_make_pdf).get_template(...)
    when(_make_pdf).get_index_file(...)
    when(_make_pdf).get_settings(...)
    _make_pdf._build_folder(ctx)
    verifyStubbedInvocationsAreUsed()
Beispiel #25
0
def test_start_process(dummy_kwargs):
    command = mock()
    when(command).run(async_=True)
    context = _run_context.RunContext(**dummy_kwargs)
    setattr(context, '_command', command)
    assert context.start_time == 0
    verifyZeroInteractions()
    context.start_process()
    assert context.start_time != 0
    verifyStubbedInvocationsAreUsed()
    verifyNoUnwantedInteractions()
def test_markdown_preprocessor():
    ctx = Context()
    index_file = Path('./index.md')
    index_file.write_text('', encoding='utf8')
    ctx.index_file = index_file
    ctx.includes = []
    ctx.markdown_text = ''
    when(_markdown).process_aliases(ctx)
    when(_markdown).process_images(ctx)
    when(_markdown).process_references(ctx)
    _markdown.process_markdown(ctx)
    verifyStubbedInvocationsAreUsed()
Beispiel #27
0
def test_find_mod_id_from_mod_id(api: Api):
    when(api)._find_mod_id_by_slug(...).thenReturn(("id", "mod-id"))

    expected_site = Site(Sites.modrinth, "id", "mod-id")
    expected_mod = Mod("mod-id", "")
    mod = Mod("mod-id", "")
    result = api.find_mod_id(mod)

    verifyStubbedInvocationsAreUsed()

    assert expected_site == result
    assert expected_mod == mod
Beispiel #28
0
def test_find_mod_id_use_slug_directly_when_available(api: Api):
    when(api)._find_mod_id_by_slug("slug", set(["slug"])).thenReturn(
        ("id", "slug"))

    expected = Site(Sites.modrinth, "id", "slug")
    input = Mod("",
                "",
                sites={Sites.modrinth: Site(Sites.modrinth, None, "slug")})
    result = api.find_mod_id(input)

    verifyStubbedInvocationsAreUsed()

    assert result == expected
Beispiel #29
0
def test_get_versions(test: TestGetVersions, repo_impl: RepoImpl):
    print(test.name)

    # Mocks API
    mock_get_all_versions(repo_impl.apis[0], test.curse_api_returns)
    mock_get_all_versions(repo_impl.apis[1], test.modrinth_api_returns)

    result = repo_impl.get_versions(test.mod)

    assert sorted(test.expected) == sorted(result)

    verifyStubbedInvocationsAreUsed()
    unstub()
def test_get_all_versions_directly_when_we_have_mod_id(api: ModrinthApi, versions_result):
    when(api.downloader).get(...).thenReturn(versions_result)
    expected = [
        VersionInfo(
            stability=Stabilities.beta,
            mod_loaders=set([ModLoaders.fabric]),
            site=Sites.modrinth,
            name="Fabric API",
            upload_time=1618769767,
            minecraft_versions=["21w16a"],
            download_url="https://cdn.modrinth.com/data/P7dR8mSH/versions/0.33.0+1.17/fabric-api-0.33.0+1.17.jar",
            filename="fabric-api-0.33.0+1.17.jar",
        ),
        VersionInfo(
            stability=Stabilities.release,
            mod_loaders=set([]),
            site=Sites.modrinth,
            name="Fabric API",
            upload_time=1618768763,
            minecraft_versions=["1.16.5"],
            download_url="https://cdn.modrinth.com/data/P7dR8mSH/versions/0.33.0+1.16/fabric-api-0.33.0+1.16.jar",
            filename="fabric-api-0.33.0+1.16.jar",
        ),
        VersionInfo(
            stability=Stabilities.alpha,
            mod_loaders=set([ModLoaders.forge]),
            site=Sites.modrinth,
            name="Fabric API",
            upload_time=1618429021,
            minecraft_versions=["21w15a"],
            download_url="https://cdn.modrinth.com/data/P7dR8mSH/versions/0.32.9+1.17/fabric-api-0.32.9+1.17.jar",
            filename="fabric-api-0.32.9+1.17.jar",
        ),
        VersionInfo(
            stability=Stabilities.release,
            mod_loaders=set([ModLoaders.fabric, ModLoaders.forge]),
            site=Sites.modrinth,
            name="Fabric API",
            upload_time=1618427403,
            minecraft_versions=["1.16.5"],
            download_url="https://cdn.modrinth.com/data/P7dR8mSH/versions/0.32.9+1.16/fabric-api-0.32.9+1.16.jar",
            filename="fabric-api-0.32.9+1.16.jar",
        ),
    ]

    versions = api.get_all_versions(mod())

    verifyStubbedInvocationsAreUsed()
    unstub()

    assert expected == versions
def test_dont_set_mod_loader(mock_repo):
    install = Install(mock_repo)
    installed_mods = []

    input = ModArg("")
    expected_mod = [Mod("", "")]
    when(mock_repo).is_installed(...).thenReturn(False)
    when(mock_repo).get_all_mods(...).thenReturn(installed_mods)
    when(install).find_download_and_install(expected_mod)

    install.execute([input])

    verifyStubbedInvocationsAreUsed()
    unstub()
Beispiel #32
0
def _global_tear_down(tmpdir, monkeypatch):
    """
    Maintains a sane environment between tests
    """
    try:
        monkeypatch.delenv('APPVEYOR')
    except KeyError:
        pass
    current_dir = os.getcwd()
    folder = Path(tmpdir).absolute()
    os.chdir(folder)
    yield
    verifyStubbedInvocationsAreUsed()
    unstub()
    os.chdir(current_dir)
Beispiel #33
0
def test_mod_not_found_uses_all_possible_names(api: Api):
    input = Mod("unearthed-fabric", "", file="some-filename")

    when(api)._find_mod_id_by_slug("unearthed-fabric",
                                   input.get_possible_slugs())
    when(api)._find_mod_id_by_slug("unearthed", input.get_possible_slugs())
    when(api)._find_mod_id_by_slug("fabric", input.get_possible_slugs())
    when(api)._find_mod_id_by_slug("some", input.get_possible_slugs())

    with pytest.raises(ModNotFoundException) as e:
        api.find_mod_id(input)

    assert e.type == ModNotFoundException

    verifyStubbedInvocationsAreUsed()
Beispiel #34
0
def test_search_for_mod(test: TestSearchForMod, repo_impl: RepoImpl):
    print(test.name)

    mock_find_mod_id(repo_impl.apis[0], test.curse_api_returns)
    mock_find_mod_id(repo_impl.apis[1], test.modrinth_api_returns)

    if test.expected == ModNotFoundException:
        with pytest.raises(ModNotFoundException) as e:
            repo_impl.search_for_mod(test.mod)
        assert test.expected == e.type
    else:
        result = repo_impl.search_for_mod(test.mod)
        assert test.expected == result

    verifyStubbedInvocationsAreUsed()
    unstub()
Beispiel #35
0
def test_on_version_found(name: str, old: Union[str, None], new: Union[str,
                                                                       None],
                          pretend: bool, expected: bool, mock_repo):
    print(name)

    config.pretend = pretend
    if expected:
        when(mock_repo).remove_mod_file(old)

    update = Update(mock_repo)
    old_mod = Mod("", "", file=old)
    new_mod = Mod("", "", file=new)
    update.on_version_found(old_mod, new_mod)

    config.pretend = False
    verifyStubbedInvocationsAreUsed()
    unstub()
 def testBarkOnUnusedStub(self):
     when(Dog).bark('Miau')
     with pytest.raises(VerificationError):
         verifyStubbedInvocationsAreUsed(Dog)
        def testWildacardCallSignatureOnStub(self):
            dog = mock()
            when(dog).waggle(Ellipsis).thenReturn('Sure')
            verify(dog, times=0).waggle(1)

            verifyStubbedInvocationsAreUsed(dog)
        def testPassIfImplicitlyVerified(self, verification):
            dog = mock()
            expect(dog, **verification).waggle().thenReturn('Sure')

            verifyStubbedInvocationsAreUsed(dog)
 def testPassUsedOnceImplicitAnswer(self):
     when(Dog).bark('Miau')
     rex = Dog()
     rex.bark('Miau')
     verifyStubbedInvocationsAreUsed(Dog)
    def testPassUsedOnce(self):
        dog = mock()
        when(dog).waggle().thenReturn('Sure')

        dog.waggle()
        verifyStubbedInvocationsAreUsed(dog)
 def testFailSecondAnswerUnused(self):
     when(Dog).bark('Miau').thenReturn('Yep').thenReturn('Nop')
     rex = Dog()
     rex.bark('Miau')
     with pytest.raises(VerificationError):
         verifyStubbedInvocationsAreUsed(Dog)