def test_parse_with_package_with_version(): """Test to parse yaml file without any package""" history = History.parse({ "name": "environment-name", "channels": ["conda-forge", "main"], "packages": { "conda": { "pytest": "3.7=py36_0" } }, "logs": ["conda create --name test pytest=3.7=py36_0"], "actions": ["conda create --name test pytest=3.7=py36_0"], "debug": [{ "platform": "osx", "conda_version": "4.5.12" }], }) assert history.name == "environment-name" assert history.channels == ["conda-forge", "main"] assert history.packages == { "conda": { "pytest": Package.from_spec("pytest=3.7=py36_0") } } assert history.logs == ["conda create --name test pytest=3.7=py36_0"] assert history.actions == ["conda create --name test pytest=3.7=py36_0"] assert history.debug == [{"platform": "osx", "conda_version": "4.5.12"}]
def get_history(self) -> Optional[History]: """return history from history.yaml""" log_file = self.env_dir / "history.yaml" if log_file.is_file(): log_content = log_file.read_text() return History.parse(yaml.load(log_content, Loader=yaml.FullLoader)) return None
def test_parse_with_package(): """Test to parse yaml file without any package""" history = History.parse({ "channels": ["conda-forge", "main"], "packages": { "conda": { "pytest": "*" } }, "logs": ["conda create --name test pytest"], "actions": [ "conda create --name test pytest=0.1=py36_0 " "--channel conda-forge " "--channel main" ], "debug": [{ "platform": "linux", "conda_version": "4.5.11" }], }) assert ["conda-forge", "main"] == history.channels assert { "conda": { "pytest": Package.from_spec("pytest") } } == history.packages assert ["conda create --name test pytest"] == history.logs assert [ "conda create --name test pytest=0.1=py36_0 " "--channel conda-forge " "--channel main" ] == history.actions assert [{"platform": "linux", "conda_version": "4.5.11"}] == history.debug
def test_export(mocker): name = "test-export" io_mock = mocker.patch("conda_env_tracker.env.EnvIO") mocker.patch( "conda_env_tracker.env.get_dependencies", mocker.Mock( return_value={ "conda": { "python": Package("python", "python=3.7.2=buildstr", "3.7.2", "buildstr") }, "pip": {}, }), ) mocker.patch("conda_env_tracker.history.get_pip_version", mocker.Mock(return_value="18.1")) history = History.parse({ "name": name, "channels": ["conda-forge", "main"], "packages": { "conda": { "python": "3.7.2=buildstr" } }, "logs": ["conda create --name test python=3.7"], "actions": ["conda create --name test python=3.7.2=buildstr"], "debug": [{ "platform": "osx", "conda_version": "4.6.1", "pip_version": "18.1" }], }) env = Environment(name=name, history=history) env.export() expected = """name: test-export channels: - conda-forge - main - nodefaults dependencies: - python=3.7.2=buildstr """ assert io_mock.mock_calls == [ mocker.call(env_directory=Path(USER_ENVS_DIR / name)), mocker.call().write_history_file(history=history), mocker.call().export_packages( contents=expected.replace("=buildstr", "")), mocker.call().delete_install_r(), ]
def test_parse_without_package(): """Test to parse yaml file without any package""" history = History.parse({ "channels": None, "packages": None, "logs": None, "actions": None, "debug": None, }) assert [] == history.channels assert {} == history.packages assert [] == history.logs assert [] == history.actions assert [] == history.debug