From c337d1d59526fb8dfe569d49bfd355c64bbf07eb Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 8 Jun 2020 08:00:28 +0300 Subject: 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. --- files.py | 9 +++++++++ files.yaml | 3 +++ 2 files changed, 12 insertions(+) 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\S+) contains "(?P.+)" function: file_contains regex: true -- cgit v1.2.1