From 7ff3cd36a19eb506848689d8dfe8291816764b82 Mon Sep 17 00:00:00 2001 From: Andrew Ferrier Date: Mon, 16 Mar 2015 23:48:02 +0000 Subject: [PATCH] Add assert in tests to validate whether outputFile already exists. --- tests/BaseTestClasses.py | 4 +++- tests/Subprocess/test_Subprocess_Basic.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/BaseTestClasses.py b/tests/BaseTestClasses.py index 8bc3989..435e35e 100644 --- a/tests/BaseTestClasses.py +++ b/tests/BaseTestClasses.py @@ -109,7 +109,7 @@ def addHeaders(self, frm=DEFAULT_FROM, to=DEFAULT_TO, subject=DEFAULT_SUBJECT): self.msg['Date'] = formatdate() - def invokeAsSubprocess(self, inputFile=False, outputDirectory=None, outputFile=None, extraParams=[], expectOutput=False): + def invokeAsSubprocess(self, inputFile=False, outputDirectory=None, outputFile=None, extraParams=[], expectOutput=False, okToExist=False): bytesMessage = self.msg.as_bytes() options = [Email2PDFTestCase.COMMAND] @@ -130,6 +130,8 @@ def invokeAsSubprocess(self, inputFile=False, outputDirectory=None, outputFile=N if outputFile: options.extend(['-o', outputFile]) + if not okToExist: + assert(not os.path.exists(outputFile)) options.extend(extraParams) diff --git a/tests/Subprocess/test_Subprocess_Basic.py b/tests/Subprocess/test_Subprocess_Basic.py index 5c57a47..4b1dbc0 100644 --- a/tests/Subprocess/test_Subprocess_Basic.py +++ b/tests/Subprocess/test_Subprocess_Basic.py @@ -113,7 +113,7 @@ def test_plaincontent_outputfileoverrides(self): def test_plaincontent_fileexist(self): self.setPlainContent("Hello!") with tempfile.NamedTemporaryFile() as tmpfile: - (rc, output, error) = self.invokeAsSubprocess(outputFile=tmpfile.name) + (rc, output, error) = self.invokeAsSubprocess(outputFile=tmpfile.name, okToExist=True) self.assertEqual(2, rc) self.assertRegex(error, "file.*exist")