Beispiel #1
0
    def test_env_export_with_variables(self):
        """
            Test conda env export
        """

        run_conda_command(Commands.CREATE, test_env_name_2, "flask")
        assert env_is_created(test_env_name_2)

        run_env_command(Commands.ENV_CONFIG, test_env_name_2, "vars", "set",
                        "DUDE=woah", "SWEET=yaaa", "-n", test_env_name_2)

        snowflake, e, = run_env_command(Commands.ENV_EXPORT, test_env_name_2)

        with Utf8NamedTemporaryFile(mode="w", suffix=".yml",
                                    delete=False) as env_yaml:
            env_yaml.write(snowflake)
            env_yaml.flush()
            env_yaml.close()

            run_env_command(Commands.ENV_REMOVE, test_env_name_2)
            self.assertFalse(env_is_created(test_env_name_2))
            run_env_command(Commands.ENV_CREATE, None, "--file", env_yaml.name)
            self.assertTrue(env_is_created(test_env_name_2))

            snowflake, e = run_env_command(Commands.ENV_EXPORT,
                                           test_env_name_2, '--no-builds')
            assert not e.strip()
            env_description = yaml_safe_load(snowflake)
            assert len(env_description['variables'])
            assert env_description['variables'].keys()

        run_env_command(Commands.ENV_REMOVE, test_env_name_2)
        assert not env_is_created(test_env_name_2)
Beispiel #2
0
    def test_env_export(self):
        """
            Test conda env export
        """

        run_conda_command(Commands.CREATE, test_env_name_2, "flask")
        assert env_is_created(test_env_name_2)

        snowflake, e, = run_env_command(Commands.ENV_EXPORT, test_env_name_2)

        with Utf8NamedTemporaryFile(mode="w", suffix=".yml",
                                    delete=False) as env_yaml:
            env_yaml.write(snowflake)
            env_yaml.flush()
            env_yaml.close()

            run_env_command(Commands.ENV_REMOVE, test_env_name_2)
            self.assertFalse(env_is_created(test_env_name_2))
            run_env_command(Commands.ENV_CREATE, None, "--file", env_yaml.name)
            self.assertTrue(env_is_created(test_env_name_2))

            # regression test for #6220
            snowflake, e, = run_env_command(Commands.ENV_EXPORT,
                                            test_env_name_2, '--no-builds')
            assert not e.strip()
            env_description = yaml_safe_load(snowflake)
            assert len(env_description["dependencies"])
            for spec_str in env_description["dependencies"]:
                assert spec_str.count("=") == 1

        run_env_command(Commands.ENV_REMOVE, test_env_name_2)
        assert not env_is_created(test_env_name_2)
Beispiel #3
0
def from_yaml(yamlstr, **kwargs):
    """Load and return a ``Environment`` from a given ``yaml string``"""
    data = yaml_safe_load(yamlstr)
    data = validate_keys(data, kwargs)

    if kwargs is not None:
        for key, value in kwargs.items():
            data[key] = value

    return Environment(**data)