summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-06-08 08:00:28 +0300
committerLars Wirzenius <liw@liw.fi>2020-06-08 08:05:45 +0300
commitc337d1d59526fb8dfe569d49bfd355c64bbf07eb (patch)
treea4b5eee22ac9a441405ed8b175e8d356f4f97383
parentbba22e1f86967feebf94ebac327f7489c1029afd (diff)
downloadsubplot-c337d1d59526fb8dfe569d49bfd355c64bbf07eb.tar.gz
test(files): add binding and function for comparing file contents
This will be used soon by a program to extract data files from subplots, but I expect it to be more generally useful in the future.
-rw-r--r--files.py9
-rw-r--r--files.yaml3
2 files changed, 12 insertions, 0 deletions
diff --git a/files.py b/files.py
index 9ee1739..1a7451f 100644
--- a/files.py
+++ b/files.py
@@ -50,6 +50,15 @@ def file_matches(ctx, filename=None, regex=None):
assert_eq(bool(m), True)
+# Check that two files have the same content
+def files_match(ctx, filename1=None, filename2=None):
+ with open(filename1, "rb") as f:
+ data1 = f.read()
+ with open(filename2, "rb") as f:
+ data2 = f.read()
+ assert_eq(data1, data2)
+
+
# Check that a file contains a fixed string.
def file_contains(ctx, filename=None, pattern=None):
with open(filename) as f:
diff --git a/files.yaml b/files.yaml
index 2cc53e1..4fc44ac 100644
--- a/files.yaml
+++ b/files.yaml
@@ -21,6 +21,9 @@
function: file_matches
regex: true
+- then: files {filename1} and {filename2} match
+ function: files_match
+
- then: file (?P<filename>\S+) contains "(?P<pattern>.+)"
function: file_contains
regex: true