-- -- --- --- --- --- --- --- ------- ------- ------- |
import json
-- -- --- --- --- --- --- --- ------- ------- ------- |
import pathlib
-- -- --- --- --- --- --- --- ------- ------- ------- |
import sys
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
import pytest
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
from wily import cache
-- -- --- --- --- --- --- --- ------- ------- ------- |
from wily.archivers import ARCHIVER_GIT, Revision
-- -- --- --- --- --- --- --- ------- ------- ------- |
from wily.config import DEFAULT_CONFIG
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
def test_exists(tmpdir):
-- -- 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
"""
-- -- 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
Test that exists() returns true if path does exist
-- -- 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
"""
-- -- 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
config = DEFAULT_CONFIG
-- -- 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
config.cache_path = tmpdir
-- -- 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
assert cache.exists(config)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 004 004 008 005 012 0027.86 0027.86 0001.00 |
def test_exists_older(tmpdir):
-- -- 001 004 004 008 005 012 0027.86 0027.86 0001.00 |
"""
-- -- 001 004 004 008 005 012 0027.86 0027.86 0001.00 |
Test that exists() returns true if path does exist
-- -- 001 004 004 008 005 012 0027.86 0027.86 0001.00 |
and has a file with the version older than the current
-- -- 001 004 004 008 005 012 0027.86 0027.86 0001.00 |
"""
-- -- 001 004 004 008 005 012 0027.86 0027.86 0001.00 |
config = DEFAULT_CONFIG
-- -- 001 004 004 008 005 012 0027.86 0027.86 0001.00 |
tmp_path = pathlib.Path(tmpdir)
-- -- 001 004 004 008 005 012 0027.86 0027.86 0001.00 |
config.cache_path = tmp_path / ".wily"
-- -- 001 004 004 008 005 012 0027.86 0027.86 0001.00 |
(tmp_path / ".wily").mkdir()
-- -- 001 004 004 008 005 012 0027.86 0027.86 0001.00 |
with open((tmp_path / ".wily" / "index.json"), "w+") as index:
-- -- 001 004 004 008 005 012 0027.86 0027.86 0001.00 |
index.write('{"version": "0.1.0"}')
-- -- 001 004 004 008 005 012 0027.86 0027.86 0001.00 |
assert cache.exists(config)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
def test_not_exists():
-- -- 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
"""
-- -- 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
Test that exists() returns false if path does not exist
-- -- 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
"""
-- -- 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
config = DEFAULT_CONFIG
-- -- 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
config.cache_path = "/v/v/w"
-- -- 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
assert not cache.exists(config)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 008 005 010 010 015 0049.83 0062.29 0001.25 |
def test_get_default_metrics_empty(tmpdir):
-- -- 002 008 005 010 010 015 0049.83 0062.29 0001.25 |
"""
-- -- 002 008 005 010 010 015 0049.83 0062.29 0001.25 |
Test that get_metrics goes ok with an empty index
-- -- 002 008 005 010 010 015 0049.83 0062.29 0001.25 |
"""
-- -- 002 008 005 010 010 015 0049.83 0062.29 0001.25 |
config = DEFAULT_CONFIG
-- -- 002 008 005 010 010 015 0049.83 0062.29 0001.25 |
tmppath = pathlib.Path(tmpdir) / ".wily"
-- -- 002 008 005 010 010 015 0049.83 0062.29 0001.25 |
config.cache_path = str(tmppath)
-- -- 002 008 005 010 010 015 0049.83 0062.29 0001.25 |
tmppath.mkdir()
-- -- 002 008 005 010 010 015 0049.83 0062.29 0001.25 |
(tmppath / "git").mkdir()
-- -- 002 008 005 010 010 015 0049.83 0062.29 0001.25 |
with open(tmppath / "git" / "index.json", "w+") as f:
-- -- 002 008 005 010 010 015 0049.83 0062.29 0001.25 |
f.write("[]")
-- -- 002 008 005 010 010 015 0049.83 0062.29 0001.25 |
-- -- 002 008 005 010 010 015 0049.83 0062.29 0001.25 |
metrics = cache.get_default_metrics(config)
-- -- 002 008 005 010 010 015 0049.83 0062.29 0001.25 |
assert metrics == []
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
def test_create_and_delete(tmpdir):
-- -- 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
"""
-- -- 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
Test that create() will create a folder with the correct path
-- -- 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
and then delete it.
-- -- 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
"""
-- -- 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
config = DEFAULT_CONFIG
-- -- 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
cache_path = pathlib.Path(tmpdir) / ".wily"
-- -- 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
config.cache_path = str(cache_path)
-- -- 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
assert not cache.exists(config)
-- -- 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
cache.create(config)
-- -- 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
assert cache.exists(config)
-- -- 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
cache.clean(config)
-- -- 002 004 003 004 006 007 0018.09 0018.09 0001.00 |
assert not cache.exists(config)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
def test_create_when_exists(tmpdir):
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
"""
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
Test that create() will continue if the folder already exists
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
"""
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
config = DEFAULT_CONFIG
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
cache_path = pathlib.Path(tmpdir) / ".wily"
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
pathlib.Path(cache_path).mkdir()
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
config.cache_path = str(cache_path)
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
assert cache.exists(config)
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
assert str(cache.create(config)) == str(cache_path)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 003 005 003 005 008 008 0024.00 0036.00 0001.50 |
def test_clean_when_not_exists(tmpdir):
-- -- 003 005 003 005 008 008 0024.00 0036.00 0001.50 |
"""
-- -- 003 005 003 005 008 008 0024.00 0036.00 0001.50 |
Test that clean() will continue if the folder does not exist
-- -- 003 005 003 005 008 008 0024.00 0036.00 0001.50 |
"""
-- -- 003 005 003 005 008 008 0024.00 0036.00 0001.50 |
config = DEFAULT_CONFIG
-- -- 003 005 003 005 008 008 0024.00 0036.00 0001.50 |
cache_path = pathlib.Path(tmpdir) / ".wily"
-- -- 003 005 003 005 008 008 0024.00 0036.00 0001.50 |
config.cache_path = str(cache_path)
-- -- 003 005 003 005 008 008 0024.00 0036.00 0001.50 |
assert not cache.exists(config)
-- -- 003 005 003 005 008 008 0024.00 0036.00 0001.50 |
assert cache.clean(config) is None
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
def test_store_basic(tmpdir):
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
config = DEFAULT_CONFIG
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
cache_path = pathlib.Path(tmpdir) / ".wily"
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
cache_path.mkdir()
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
config.cache_path = cache_path
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
target_path = str(pathlib.Path(tmpdir) / "foo" / "bar.py")
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
_TEST_STATS = {"operator_data": {"test": {target_path: {"metric1": 1}}}}
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
_TEST_REVISION = Revision(
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
key="12345",
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
author_name="Anthony Shaw",
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
author_email="anthony@test.com",
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
date="17/01/1990",
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
message="my changes",
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
tracked_files=[target_path],
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
tracked_dirs=[target_path],
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
added_files=[target_path],
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
modified_files=[target_path],
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
deleted_files=[target_path],
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
)
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
fn = cache.store(config, ARCHIVER_GIT, _TEST_REVISION, _TEST_STATS)
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
with open(fn) as cache_item:
-- 01 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
result = json.load(cache_item)
-- -- 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
assert isinstance(result, dict)
-- -- 002 008 004 008 010 012 0039.86 0039.86 0001.00 |
assert result == _TEST_STATS
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows")
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
def test_store_twice(tmpdir):
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
"""Test that you can't write the same revision twice"""
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
config = DEFAULT_CONFIG
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
cache_path = pathlib.Path(tmpdir) / ".wily"
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
cache_path.mkdir()
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
config.cache_path = cache_path
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
target_path = str(pathlib.Path(tmpdir) / "foo" / "bar.py")
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
_TEST_STATS = {"operator_data": {"test": {target_path: {"metric1": 1}}}}
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
_TEST_REVISION = Revision(
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
key="12345",
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
author_name="Anthony Shaw",
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
author_email="anthony@test.com",
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
date="17/01/1990",
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
message="my changes",
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
tracked_files=[target_path],
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
tracked_dirs=[target_path],
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
added_files=[target_path],
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
modified_files=[target_path],
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
deleted_files=[target_path],
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
)
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
fn = cache.store(config, ARCHIVER_GIT, _TEST_REVISION, _TEST_STATS)
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
with pytest.raises(RuntimeError):
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
cache.store(config, ARCHIVER_GIT, _TEST_REVISION, _TEST_STATS)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
def test_store_relative_paths(tmpdir):
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
"""
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
Test that the store command works when absolute paths are used for the targets..
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
"""
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
config = DEFAULT_CONFIG
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
cache_path = pathlib.Path(tmpdir) / ".wily"
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
target_path = str(pathlib.Path(tmpdir) / "foo" / "bar.py")
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
cache_path.mkdir()
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
config.cache_path = cache_path
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
config.path = tmpdir
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
_TEST_STATS = {"operator_data": {"test": {target_path: {"metric1": 1}}}}
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
_TEST_REVISION = Revision(
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
key="12345",
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
author_name="Anthony Shaw",
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
author_email="anthony@test.com",
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
date="17/01/1990",
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
message="my changes",
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
tracked_files=[target_path],
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
tracked_dirs=[target_path],
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
added_files=[target_path],
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
modified_files=[target_path],
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
deleted_files=[target_path],
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
)
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
fn = cache.store(config, ARCHIVER_GIT, _TEST_REVISION, _TEST_STATS)
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
with open(fn) as cache_item:
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
result = json.load(cache_item)
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
assert isinstance(result, dict)
-- 02 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
if sys.platform == "win32":
-- -- 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
assert "foo\\bar.py" in result["operator_data"]["test"].keys()
-- -- 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
else:
-- -- 003 012 006 012 015 018 0070.32 0105.49 0001.50 |
assert "foo/bar.py" in result["operator_data"]["test"].keys()
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
def test_store_index(tmpdir):
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
"""
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
Test the store index
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
"""
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
config = DEFAULT_CONFIG
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
cache_path = pathlib.Path(tmpdir) / ".wily"
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
cache_path.mkdir()
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
config.cache_path = cache_path
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
config.path = tmpdir
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
_TEST_INDEX = [{"message": "a", "date": 1234}, {"message": "b", "date": 1345}]
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
fn = cache.store_archiver_index(config, ARCHIVER_GIT, _TEST_INDEX)
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
with open(fn) as cache_item:
-- 01 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
result = json.load(cache_item)
-- -- 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
assert isinstance(result, list)
-- -- --- --- --- --- --- --- ------- ------- ------- |
assert result[0] == _TEST_INDEX[1]