summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarius Makovsky <traveltissues@protonmail.com>2019-11-11 16:14:31 +0000
committerDarius Makovsky <traveltissues@protonmail.com>2019-11-27 09:42:02 +0000
commit4fbdf61039c6ecc1134caf9e587e7934bcc5a882 (patch)
treefb5ddee056abaa66ecf63f71971bae99b8bc6d3b
parent41dc004f58696a6b44c004e6627dfd867b590280 (diff)
downloadbuildstream-4fbdf61039c6ecc1134caf9e587e7934bcc5a882.tar.gz
tests: Allow strict contents in assert_contains
-rw-r--r--src/buildstream/testing/integration.py20
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: