diff options
author | Darius Makovsky <traveltissues@protonmail.com> | 2019-11-11 16:14:31 +0000 |
---|---|---|
committer | Darius Makovsky <traveltissues@protonmail.com> | 2019-11-27 09:42:02 +0000 |
commit | 4fbdf61039c6ecc1134caf9e587e7934bcc5a882 (patch) | |
tree | fb5ddee056abaa66ecf63f71971bae99b8bc6d3b /src | |
parent | 41dc004f58696a6b44c004e6627dfd867b590280 (diff) | |
download | buildstream-4fbdf61039c6ecc1134caf9e587e7934bcc5a882.tar.gz |
tests: Allow strict contents in assert_contains
Diffstat (limited to 'src')
-rw-r--r-- | src/buildstream/testing/integration.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/buildstream/testing/integration.py b/src/buildstream/testing/integration.py index 9a1a48816..269b3d317 100644 --- a/src/buildstream/testing/integration.py +++ b/src/buildstream/testing/integration.py @@ -49,11 +49,25 @@ def walk_dir(root): # Ensure that a directory contains the given filenames. -def assert_contains(directory, expected): +# If `strict` is `True` then no additional filenames are allowed. +def assert_contains(directory, expected, strict=False): + expected = set(expected) missing = set(expected) - missing.difference_update(walk_dir(directory)) + found = set(walk_dir(directory)) + + # elements expected but not found + missing.difference_update(found) + if missing: - raise AssertionError("Missing {} expected elements from list: {}".format(len(missing), missing)) + msg = "Missing {} expected elements from list: {}".format(len(missing), missing) + raise AssertionError(msg) + + if strict: + # elements found but not expected + found.difference_update(expected) + msg = "{} additional elements were present in the directory: {}".format(len(found), found) + if found: + raise AssertionError(msg) class IntegrationCache: |