From 58260c5a2187c3242d2e904ad8fcdc0269149b0d Mon Sep 17 00:00:00 2001 From: Johan Holmberg Date: Mon, 15 Jun 2015 22:35:06 +0200 Subject: [PATCH] add 'file_equal' and 'file_match' --- python/CMDTEST_example.py | 6 ++++++ python/cmdtest.py | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/python/CMDTEST_example.py b/python/CMDTEST_example.py index ebf91ec..3aeec63 100644 --- a/python/CMDTEST_example.py +++ b/python/CMDTEST_example.py @@ -98,6 +98,12 @@ class TC_example(TestCase): ], 'utf-16') c.stdout_match("tt", 'utf-16') + c.file_equal("abc.txt", [ + 'detta är abc.txtx', + 'räksmörgås', + ], 'utf-16') + c.file_match("abc.txt", "tt", 'utf-16') + with self.cmd("true") as c: pass diff --git a/python/cmdtest.py b/python/cmdtest.py index 1bd54f0..d155819 100755 --- a/python/cmdtest.py +++ b/python/cmdtest.py @@ -63,7 +63,7 @@ def error_show(name, what, arg): try: msg = arg.error_msg(what) except: - if name.startswith('stdout_') or name.startswith('stderr_'): + if re.match(r'(stdout|stderr|file)_', name): print(what) if len(arg) == 0: print(" <>") @@ -231,6 +231,14 @@ class Result: expect = ExpectFile(self, content, encoding) expect.check("stderr_equal", self._stderr) + def file_match(self, fname, pattern, encoding='utf-8'): + expect = ExpectPattern(self, pattern, encoding) + expect.check("file_match %s" % fname, File(fname)) + + def file_equal(self, fname, content, encoding='utf-8'): + expect = ExpectFile(self, content, encoding) + expect.check("file_equal %s" % fname, File(fname)) + TESTS = { "created_files" : (lambda before,after: not before and after, {"created"}),