From 25521518589b3dabda24c0a3da2031b22bbf2f41 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Fri, 22 May 2020 17:27:44 +0530 Subject: [PATCH] Add helpers to TestPipResult --- tests/lib/__init__.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/lib/__init__.py b/tests/lib/__init__.py index 941653408..d08e1f361 100644 --- a/tests/lib/__init__.py +++ b/tests/lib/__init__.py @@ -353,6 +353,27 @@ class TestPipResult(object): .format(**locals()) ) + def did_create(self, path, message=None): + assert str(path) in self.files_created, _one_or_both(message, self) + + def did_not_create(self, path, message=None): + assert str(path) not in self.files_created, _one_or_both(message, self) + + def did_update(self, path, message=None): + assert str(path) in self.files_updated, _one_or_both(message, self) + + def did_not_update(self, path, message=None): + assert str(path) not in self.files_updated, _one_or_both(message, self) + + +def _one_or_both(a, b): + """Returns f"{a}\n{b}" if a is truthy, else returns str(b). + """ + if not a: + return str(b) + + return "{a}\n{b}".format(a=a, b=b) + def make_check_stderr_message(stderr, line, reason): """ -- GitLab