def test_store_relative_paths(tmpdir): """ Test that the store command works when absolute paths are used for the targets.. """ config = DEFAULT_CONFIG cache_path = pathlib.Path(tmpdir) / ".wily" target_path = str(pathlib.Path(tmpdir) / "foo" / "bar.py") cache_path.mkdir() config.cache_path = cache_path config.path = tmpdir _TEST_STATS = {"operator_data": {"test": {target_path: {"metric1": 1}}}} _TEST_REVISION = Revision( key="12345", author_name="Anthony Shaw", author_email="*****@*****.**", date="17/01/1990", message="my changes", ) fn = cache.store(config, ARCHIVER_GIT, _TEST_REVISION, _TEST_STATS) with open(fn) as cache_item: result = json.load(cache_item) assert isinstance(result, dict) if sys.platform == "win32": assert "foo\\bar.py" in result["operator_data"]["test"].keys() else: assert "foo/bar.py" in result["operator_data"]["test"].keys()
def test_store_twice(tmpdir): """ Test that you can't write the same revision twice """ config = DEFAULT_CONFIG cache_path = pathlib.Path(tmpdir) / ".wily" cache_path.mkdir() config.cache_path = cache_path target_path = str(pathlib.Path(tmpdir) / "foo" / "bar.py") _TEST_STATS = {"operator_data": {"test": {target_path: {"metric1": 1}}}} _TEST_REVISION = Revision( key="12345", author_name="Anthony Shaw", author_email="*****@*****.**", date="17/01/1990", message="my changes", ) fn = cache.store(config, ARCHIVER_GIT, _TEST_REVISION, _TEST_STATS) with pytest.raises(RuntimeError): cache.store(config, ARCHIVER_GIT, _TEST_REVISION, _TEST_STATS)
def store(self, config, archiver, stats): """ Store the stats for this indexed revision. :param config: The wily config. :type config: :class:`wily.config.WilyConfig` :param archiver: The archiver. :type archiver: :class:`wily.archivers.Archiver` :param stats: The data :type stats: ``dict`` """ self._data = stats return cache.store(config, archiver, self.revision, stats)
def test_store_basic(tmpdir): config = DEFAULT_CONFIG cache_path = pathlib.Path(tmpdir) / ".wily" cache_path.mkdir() config.cache_path = cache_path target_path = str(pathlib.Path(tmpdir) / "foo" / "bar.py") _TEST_STATS = {"operator_data": {"test": {target_path: {"metric1": 1}}}} _TEST_REVISION = Revision( key="12345", author_name="Anthony Shaw", author_email="*****@*****.**", date="17/01/1990", message="my changes", ) fn = cache.store(config, ARCHIVER_GIT, _TEST_REVISION, _TEST_STATS) with open(fn) as cache_item: result = json.load(cache_item) assert isinstance(result, dict) assert result == _TEST_STATS