def test_successful_no_output(): Pipeline( Run([PYTHON, "-m", "grade", "run", "-p", "test_mixins.py"]), AssertExitSuccess(), AssertStdoutMatches(""), AssertStderrMatches(""), )()
def test_inferring_filename(self): """ Can we infer filename if conventions are followed? """ results = Run(["grep", "-h"])() results = WriteOutputs("-h")(results) results = AssertStderrMatches()(results) self.assertIsInstance(results, CompletedProcess) os.remove("-h.stdout") os.remove("-h.stderr")
def test_passing_filename(): results = Run(">&2 echo hello", shell=True)() with open("hello.stderr", "w") as f: f.write("hello") AssertStderrMatches(filepath="hello.stderr")(results) os.remove("hello.stderr")
def test_passing_both(self): results = Run(">&2 echo hello", shell=True)() with self.assertRaises(ValueError): AssertStderrMatches("hello", "world")(results)
def test_cannot_infer_shell(self): """ Should not be able to infer filename when shell=True """ results = Run(">&2 echo hello_world", shell=True)() with self.assertRaises(ValueError): AssertStderrMatches()(results)
def test_cannot_infer_filename(self): """ What if there is no file to infer from? """ results = Run(["grep", "-h"])() with self.assertRaises(AssertionError): AssertStderrMatches()(results)
def test_stderr_matches(self): """ What if stderr does match? """ results = Run(">&2 echo hello_world", shell=True)() results = AssertStderrMatches("hello_world")(results) self.assertIsInstance(results, CompletedProcess)
def test_stderr_no_match(self): """ What happens when stderr does not match? """ results = Run(">&2 echo hello_world", shell=True)() with self.assertRaises(AssertionError): AssertStderrMatches("goodbye_world")(results)