summaryrefslogtreecommitdiff
path: root/tests/cachekey
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cachekey')
-rw-r--r--tests/cachekey/cachekey.py121
-rwxr-xr-xtests/cachekey/update.py29
2 files changed, 64 insertions, 86 deletions
diff --git a/tests/cachekey/cachekey.py b/tests/cachekey/cachekey.py
index fa93f5746..b669bacaa 100644
--- a/tests/cachekey/cachekey.py
+++ b/tests/cachekey/cachekey.py
@@ -62,7 +62,7 @@ def element_filename(project_dir, element_name, alt_suffix=None):
if alt_suffix:
# Just in case...
- assert element_name.endswith('.bst')
+ assert element_name.endswith(".bst")
# Chop off the 'bst' in '.bst' and add the new suffix
element_name = element_name[:-3]
@@ -93,18 +93,20 @@ def load_expected_keys(project_dir, actual_keys, raise_error=True):
expected_keys = OrderedDict()
for element_name in actual_keys:
- expected = element_filename(project_dir, element_name, 'expected')
+ expected = element_filename(project_dir, element_name, "expected")
try:
- with open(expected, 'r') as f:
+ with open(expected, "r") as f:
expected_key = f.read()
expected_key = expected_key.strip()
except FileNotFoundError:
expected_key = None
if raise_error:
- raise Exception("Cache key test needs update, " +
- "expected file {} not found.\n\n".format(expected) +
- "Use tests/cachekey/update.py to automatically " +
- "update this test case")
+ raise Exception(
+ "Cache key test needs update, "
+ + "expected file {} not found.\n\n".format(expected)
+ + "Use tests/cachekey/update.py to automatically "
+ + "update this test case"
+ )
expected_keys[element_name] = expected_key
@@ -127,13 +129,17 @@ def assert_cache_keys(project_dir, output):
if mismatches:
info = ""
for element_name in mismatches:
- info += " Element: {}\n".format(element_name) + \
- " Expected: {}\n".format(expected_keys[element_name]) + \
- " Actual: {}\n".format(actual_keys[element_name])
+ info += (
+ " Element: {}\n".format(element_name)
+ + " Expected: {}\n".format(expected_keys[element_name])
+ + " Actual: {}\n".format(actual_keys[element_name])
+ )
- raise AssertionError("Cache key mismatches occurred:\n{}\n".format(info) +
- "Use tests/cachekey/update.py to automatically " +
- "update this test case")
+ raise AssertionError(
+ "Cache key mismatches occurred:\n{}\n".format(info)
+ + "Use tests/cachekey/update.py to automatically "
+ + "update this test case"
+ )
##############################################
@@ -141,18 +147,14 @@ def assert_cache_keys(project_dir, output):
##############################################
# Project directory
-DATA_DIR = os.path.join(
- os.path.dirname(os.path.realpath(__file__)),
- "project",
-)
+DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "project",)
# The cache key test uses a project which exercises all plugins,
# so we cant run it at all if we dont have them installed.
#
-@pytest.mark.skipif(MACHINE_ARCH != 'x86-64',
- reason='Cache keys depend on architecture')
-@pytest.mark.skipif(not IS_LINUX, reason='Only available on linux')
+@pytest.mark.skipif(MACHINE_ARCH != "x86-64", reason="Cache keys depend on architecture")
+@pytest.mark.skipif(not IS_LINUX, reason="Only available on linux")
@pytest.mark.skipif(HAVE_BZR is False, reason="bzr is not available")
@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
@pytest.mark.datafiles(DATA_DIR)
@@ -163,55 +165,48 @@ def test_cache_key(datafiles, cli):
# versions of setuptools fail to preserve symbolic links
# when creating a source distribution, causing this test
# to fail from a dist tarball.
- goodbye_link = os.path.join(project, 'files', 'local',
- 'usr', 'bin', 'goodbye')
+ goodbye_link = os.path.join(project, "files", "local", "usr", "bin", "goodbye")
os.unlink(goodbye_link)
- os.symlink('hello', goodbye_link)
+ os.symlink("hello", goodbye_link)
# pytest-datafiles does not copy mode bits
# https://github.com/omarkohl/pytest-datafiles/issues/11
os.chmod(goodbye_link, 0o755)
- result = cli.run(project=project, silent=True, args=[
- 'show',
- '--format', '%{name}::%{full-key}',
- 'target.bst'
- ])
+ result = cli.run(project=project, silent=True, args=["show", "--format", "%{name}::%{full-key}", "target.bst"])
result.assert_success()
assert_cache_keys(project, result.output)
@pytest.mark.datafiles(DATA_DIR)
-@pytest.mark.parametrize("first_warnings, second_warnings, identical_keys", [
- [[], [], True],
- [[], [CoreWarnings.REF_NOT_IN_TRACK], False],
- [[CoreWarnings.REF_NOT_IN_TRACK], [], False],
- [[CoreWarnings.REF_NOT_IN_TRACK], [CoreWarnings.REF_NOT_IN_TRACK], True],
- [[CoreWarnings.REF_NOT_IN_TRACK, CoreWarnings.OVERLAPS],
- [CoreWarnings.OVERLAPS, CoreWarnings.REF_NOT_IN_TRACK], True],
-])
+@pytest.mark.parametrize(
+ "first_warnings, second_warnings, identical_keys",
+ [
+ [[], [], True],
+ [[], [CoreWarnings.REF_NOT_IN_TRACK], False],
+ [[CoreWarnings.REF_NOT_IN_TRACK], [], False],
+ [[CoreWarnings.REF_NOT_IN_TRACK], [CoreWarnings.REF_NOT_IN_TRACK], True],
+ [
+ [CoreWarnings.REF_NOT_IN_TRACK, CoreWarnings.OVERLAPS],
+ [CoreWarnings.OVERLAPS, CoreWarnings.REF_NOT_IN_TRACK],
+ True,
+ ],
+ ],
+)
def test_cache_key_fatal_warnings(cli, tmpdir, first_warnings, second_warnings, identical_keys):
# Builds project, Runs bst show, gathers cache keys
def run_get_cache_key(project_name, warnings):
- config = {
- 'name': project_name,
- 'element-path': 'elements',
- 'fatal-warnings': warnings
- }
+ config = {"name": project_name, "element-path": "elements", "fatal-warnings": warnings}
project_dir = tmpdir.mkdir(project_name)
- project_config_file = str(project_dir.join('project.conf'))
+ project_config_file = str(project_dir.join("project.conf"))
_yaml.roundtrip_dump(config, file=project_config_file)
- elem_dir = project_dir.mkdir('elements')
- element_file = str(elem_dir.join('stack.bst'))
- _yaml.roundtrip_dump({'kind': 'stack'}, file=element_file)
+ elem_dir = project_dir.mkdir("elements")
+ element_file = str(elem_dir.join("stack.bst"))
+ _yaml.roundtrip_dump({"kind": "stack"}, file=element_file)
- result = cli.run(project=str(project_dir), args=[
- 'show',
- '--format', '%{name}::%{full-key}',
- 'stack.bst'
- ])
+ result = cli.run(project=str(project_dir), args=["show", "--format", "%{name}::%{full-key}", "stack.bst"])
return result.output
# Returns true if all keys are identical
@@ -226,34 +221,20 @@ def test_cache_key_fatal_warnings(cli, tmpdir, first_warnings, second_warnings,
@pytest.mark.datafiles(DATA_DIR)
def test_keys_stable_over_targets(cli, datafiles):
- root_element = 'elements/key-stability/top-level.bst'
- target1 = 'elements/key-stability/t1.bst'
- target2 = 'elements/key-stability/t2.bst'
+ root_element = "elements/key-stability/top-level.bst"
+ target1 = "elements/key-stability/t1.bst"
+ target2 = "elements/key-stability/t2.bst"
project = str(datafiles)
- full_graph_result = cli.run(project=project, args=[
- 'show',
- '--format', '%{name}::%{full-key}',
- root_element
- ])
+ full_graph_result = cli.run(project=project, args=["show", "--format", "%{name}::%{full-key}", root_element])
full_graph_result.assert_success()
all_cache_keys = parse_output_keys(full_graph_result.output)
- ordering1_result = cli.run(project=project, args=[
- 'show',
- '--format', '%{name}::%{full-key}',
- target1,
- target2
- ])
+ ordering1_result = cli.run(project=project, args=["show", "--format", "%{name}::%{full-key}", target1, target2])
ordering1_result.assert_success()
ordering1_cache_keys = parse_output_keys(ordering1_result.output)
- ordering2_result = cli.run(project=project, args=[
- 'show',
- '--format', '%{name}::%{full-key}',
- target2,
- target1
- ])
+ ordering2_result = cli.run(project=project, args=["show", "--format", "%{name}::%{full-key}", target2, target1])
ordering2_result.assert_success()
ordering2_cache_keys = parse_output_keys(ordering2_result.output)
diff --git a/tests/cachekey/update.py b/tests/cachekey/update.py
index feda5dbde..49af39fe1 100755
--- a/tests/cachekey/update.py
+++ b/tests/cachekey/update.py
@@ -25,31 +25,28 @@ except ImportError:
from .cachekey import element_filename, parse_output_keys, load_expected_keys
# Project directory
-PROJECT_DIR = os.path.join(
- os.path.dirname(os.path.realpath(__file__)),
- "project",
-)
+PROJECT_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "project",)
def write_expected_key(element_name, actual_key):
- expected_file = element_filename(PROJECT_DIR, element_name, 'expected')
- with open(expected_file, 'w') as f:
+ expected_file = element_filename(PROJECT_DIR, element_name, "expected")
+ with open(expected_file, "w") as f:
f.write(actual_key)
def update_keys():
with tempfile.TemporaryDirectory(dir=PROJECT_DIR) as tmpdir:
- directory = os.path.join(tmpdir, 'cache')
+ directory = os.path.join(tmpdir, "cache")
os.makedirs(directory)
cli = Cli(directory, verbose=True)
# Run bst show
- result = cli.run(project=PROJECT_DIR, silent=True, args=[
- '--no-colors',
- 'show', '--format', '%{name}::%{full-key}',
- 'target.bst'
- ])
+ result = cli.run(
+ project=PROJECT_DIR,
+ silent=True,
+ args=["--no-colors", "show", "--format", "%{name}::%{full-key}", "target.bst"],
+ )
# Load the actual keys, and the expected ones if they exist
if not result.output:
@@ -59,7 +56,7 @@ def update_keys():
expected_keys = load_expected_keys(PROJECT_DIR, actual_keys, raise_error=False)
for element_name in actual_keys:
- expected = element_filename(PROJECT_DIR, element_name, 'expected')
+ expected = element_filename(PROJECT_DIR, element_name, "expected")
if actual_keys[element_name] != expected_keys[element_name]:
if not expected_keys[element_name]:
@@ -70,10 +67,10 @@ def update_keys():
write_expected_key(element_name, actual_keys[element_name])
-if __name__ == '__main__':
+if __name__ == "__main__":
# patch the environment BST_TEST_SUITE value to something if it's not
# present. This avoids an exception thrown at the cli level
- bst = 'BST_TEST_SUITE'
- mock_bst = os.environ.get(bst, 'True')
+ bst = "BST_TEST_SUITE"
+ mock_bst = os.environ.get(bst, "True")
with mock.patch.dict(os.environ, {**os.environ, bst: mock_bst}):
update_keys()