Beispiel #1
0
    def test_config_search_list(self, config_deps: Mock, config: VenvConfig):
        config.search_path(['Test', 'Path'])

        config.load()

        config_deps.exists.assert_any_call(Path('Test').absolute() / '.sv_cfg')
        config_deps.exists.assert_any_call(Path('Path').absolute() / '.sv_cfg')
Beispiel #2
0
    def test_venv_config_venvs(self, config_deps: Mock,
                               config: VenvConfig) -> None:
        config_read(config_deps, {self.CWD_sv_cfg: "[sample]\n[pip]\n"})

        config.load()

        assert {'sample', 'pip'} <= set(config.venvs)
Beispiel #3
0
    def test_venv_local(self, config_deps: Mock, config: VenvConfig) -> None:
        config_read(config_deps,
                    {self.CWD_sv_cfg: "[pip.test]\nlocation = ~\n"})

        config.load()

        assert path.join('~', '.sv') in str(config.venvs['pip.test'])
Beispiel #4
0
    def test_list_basic(self, config_deps: Mock, config: VenvConfig) -> None:
        config_read(config_deps, {self.CWD_sv_cfg: "[test]\n"})

        config.load()
        config.list()

        config_deps.echo.assert_called_with(
            path.join('test (.sv', 'test) [.sv_cfg]'))
Beispiel #5
0
    def test_venv_config_scripts(self, config_deps: Mock,
                                 config: VenvConfig) -> None:
        config_read(
            config_deps,
            {self.CWD_sv_cfg: "[SCRIPTS]\nsample.py=sample\npip=sample"})

        config.load()

        assert {'sample.py', 'pip'} <= set(config.scripts)
Beispiel #6
0
    def test_venv_config_ignored(self, config_deps: Mock,
                                 config: VenvConfig) -> None:
        config_read(config_deps, {self.CWD_sv_cfg: "[Sample]\n[pip.Test]\n"})

        config.load()

        assert not config.venvs
        config_deps.echo.assert_called_with(
            StringContaining("Sample, pip.Test"))
Beispiel #7
0
    def test_list_scripts(self, config_deps: Mock, config: VenvConfig) -> None:
        config_read(
            config_deps,
            {self.CWD_sv_cfg: "[SCRIPTS]\nsample = test\ntester = test"})
        config.load()

        config.list()

        config_deps.echo.assert_called_with("\tScripts: sample, tester")
Beispiel #8
0
    def test_create_missing(self, config_deps: Mock,
                            config: VenvConfig) -> None:
        config_read(config_deps, {self.CWD_sv_cfg: "[test]"})
        config.load()

        config.create('other')

        config_deps.echo.assert_called_with(
            "Unable to find venv or script other")
Beispiel #9
0
    def test_create_exists(self, venv_deps: Mock, config_deps: Mock,
                           config: VenvConfig) -> None:
        config_read(config_deps, {self.CWD_sv_cfg: "[test]"})
        venv_exists(venv_deps, self.CWD_sv_test)
        config.load()

        config.create('test')

        venv_deps.echo.assert_not_called()
Beispiel #10
0
    def test_list_prerequisites(self, config_deps: Mock,
                                config: VenvConfig) -> None:
        config_read(
            config_deps,
            {self.CWD_sv_cfg: "[test]\nprerequisites = beta\n\talpha\n"})
        config.load()

        config.list()

        config_deps.echo.assert_called_with("\tPrerequisites: alpha\n\t\tbeta")
Beispiel #11
0
    def test_venv_prerequisites(self, config_deps: Mock,
                                config: VenvConfig) -> None:
        config_read(
            config_deps,
            {self.CWD_sv_cfg: "[sample]\nprerequisites = first\n\tsecond\n"})

        config.load()

        venv = config.venvs['sample']
        assert {'first', 'second'} == venv.prerequisites
Beispiel #12
0
    def test_venv_config_load(self, config_deps: Mock,
                              config: VenvConfig) -> None:
        config_read(config_deps,
                    {self.CWD_sv_cfg: "[SCRIPTS]\nsample.py=sample"})

        config.load()

        assert 'sample.py' in config.scripts
        assert 'sample' in config.venvs
        assert 'sample' == config.scripts['sample.py']
Beispiel #13
0
    def test_create_update(self, venv_deps: Mock, config_deps: Mock,
                           config: VenvConfig) -> None:
        config_read(config_deps, {self.CWD_sv_cfg: "[test]"})
        venv_exists(venv_deps, self.CWD_sv_test)
        config.load()

        config.create('test', update=True)

        venv_deps.echo.assert_called_with(
            StringContaining("Updating venv test"))
Beispiel #14
0
    def test_venv_requirements(self, config_deps: Mock,
                               config: VenvConfig) -> None:
        config_read(
            config_deps,
            {self.CWD_sv_cfg: "[sample]\nrequirements = alpha\n\tbeta\n"})

        config.load()

        venv = config.venvs['sample']
        assert {'alpha', 'beta'} == venv.requirements
Beispiel #15
0
    def test_create_script(self, venv_deps: Mock, config_deps: Mock,
                           config: VenvConfig) -> None:
        venv_exists(venv_deps)
        config_read(config_deps, {self.CWD_sv_cfg: "[SCRIPTS]\ntester = test"})
        config.load()

        config.create('tester')

        venv_deps.echo.assert_called_with(
            StringContaining("Creating venv test"))
Beispiel #16
0
    def test_list_requirements(self, config_deps: Mock,
                               config: VenvConfig) -> None:
        config_read(
            config_deps,
            {self.CWD_sv_cfg: "[test]\nrequirements = second\n\tfirst\n"})
        config.load()

        config.list()

        config_deps.echo.assert_called_with(
            "\tRequirements: first\n\t\tsecond")
Beispiel #17
0
    def test_register_global(self, config_deps: Mock,
                             config: VenvConfig) -> None:
        config_read(config_deps, {})
        config_write(config_deps)
        config_scripts(config_deps)

        config.register('test', ('package', ), config_path='~/.config')

        config_deps.echo.assert_called_with(StringContaining("Registering"))
        assert self.USER_sv_cfg in config_deps.out_str
        out_str = config_deps.out_str[self.USER_sv_cfg]
        assert "requirements = package" in out_str
Beispiel #18
0
    def test_register(self, config_deps: Mock, config: VenvConfig) -> None:
        config_read(config_deps, {})
        config_write(config_deps)
        config_scripts(config_deps)

        config.register('test', ('package', ))

        config_deps.echo.assert_called_with(StringContaining("Registering"))
        sv_cfg = path.abspath('.sv_cfg')
        assert sv_cfg in config_deps.out_str
        out_str = config_deps.out_str[sv_cfg]
        assert "[test]" in out_str
        assert "requirements = package" in out_str
        assert "global" not in out_str
        assert "local" not in out_str
Beispiel #19
0
    def test_register_scripts(self, config_deps: Mock,
                              config: VenvConfig) -> None:
        config_read(config_deps, {})
        config_write(config_deps)
        config_scripts(config_deps)

        config.register('test', ('package1', 'package2'), config_path='Test')

        config_deps.echo.assert_called_with(StringContaining("Registering"))
        test_sv_cfg = path.expandvars(path.join('$CWD', 'Test', '.sv_cfg'))
        assert test_sv_cfg in config_deps.out_str
        out_str = config_deps.out_str[test_sv_cfg]
        assert "package1.script = test" in out_str
        assert "package2.script = test" in out_str
        assert "requirements = package1\n\tpackage2" in out_str
Beispiel #20
0
def test_register_scripts(venv_config: VenvConfig) -> None:
    out_file = StringIO()

    def test_scripts(package: str) -> Iterable[str]:
        return [package + '.script']

    venv_config.register('test', ('package1', 'package2'),
                         False,
                         False,
                         out_file=out_file,
                         package_scripts=test_scripts)

    out_str = out_file.getvalue()
    assert "package1.script = test" in out_str
    assert "package2.script = test" in out_str
    assert "requirements = package1\n\tpackage2" in out_str
Beispiel #21
0
def test_register_global(venv_config: VenvConfig) -> None:
    out_file = StringIO()

    def test_scripts(_package: str) -> Iterable[str]:
        return []

    venv_config.register('test', ('package', ),
                         False,
                         False,
                         out_file=out_file,
                         package_scripts=test_scripts)

    out_str = out_file.getvalue()
    assert "global\n" in out_str
    assert "requirements = package" in out_str
    assert "local" not in out_str
Beispiel #22
0
    def test_register_existing(self, config_deps: Mock,
                               config: VenvConfig) -> None:
        config_read(
            config_deps, {
                self.CWD_sv_cfg:
                """[SCRIPTS]\nsample = test\n\n[test]\nprerequisites = early\nrequirements = old\n"""
            })
        config_write(config_deps)
        config_scripts(config_deps)

        config.register('test', ('new', ), config_path='.')

        config_deps.echo.assert_called_with(StringContaining("Registering"))
        assert self.CWD_sv_cfg in config_deps.out_str
        out_str = config_deps.out_str[self.CWD_sv_cfg]
        assert "[test]" in out_str
        assert "[SCRIPTS]" in out_str
        assert "prerequisites = early" in out_str
        assert "requirements = new\n\told" in out_str
        assert "global" not in out_str
        assert "local" not in out_str
Beispiel #23
0
def test_venv_local(venv_config: VenvConfig) -> None:
    venv_config.load(True, in_file=StringIO("[pip.test]\nlocal"))

    assert '~' not in str(venv_config.venvs['pip.test'])
Beispiel #24
0
def test_venv_current(venv_config: VenvConfig) -> None:
    venv_config.load(False, in_file=StringIO("[pip.test]\n"))

    assert '~' not in str(venv_config.venvs['pip.test'])
Beispiel #25
0
def test_venv_global(venv_config: VenvConfig) -> None:
    venv_config.load(False, in_file=StringIO("[pip.test]\nglobal"))

    assert '~' in str(venv_config.venvs['pip.test'])
Beispiel #26
0
def venv_config_venvs(venv_config: VenvConfig) -> None:
    venv_config.load(False, in_file=StringIO("[sample]\n[pip]"))

    assert {'sample', 'pip'} <= set(venv_config.venvs)
Beispiel #27
0
def venv_config_scripts(venv_config: VenvConfig) -> None:
    venv_config.load(
        False, in_file=StringIO("[SCRIPTS]\nsample.py=sample\npip=sample"))

    assert {'pip', 'sample.py'} <= set(venv_config.scripts)
Beispiel #28
0
def venv_config_load(venv_config: VenvConfig) -> None:
    venv_config.load(False, in_file=StringIO("[SCRIPTS]\nsample.py=sample"))

    assert 'sample.py' in venv_config.scripts
    assert 'sample' in venv_config.venvs
    assert 'sample' == venv_config.scripts['sample.py']
Beispiel #29
0
def venv_config() -> VenvConfig:
    return VenvConfig()
Beispiel #30
0
 def config(self, config_deps: ConfigDependencies) -> VenvConfig:
     return VenvConfig(deps=config_deps)