added clitest for failing test
Showing
1 changed file
with
29 additions
and
5 deletions
... | @@ -36,20 +36,27 @@ class CasperExecTest(unittest.TestCase): | ... | @@ -36,20 +36,27 @@ class CasperExecTest(unittest.TestCase): |
36 | with open(os.path.join(CASPERJS_ROOT, 'package.json')) as f: | 36 | with open(os.path.join(CASPERJS_ROOT, 'package.json')) as f: |
37 | self.pkg_version = json.load(f).get('version') | 37 | self.pkg_version = json.load(f).get('version') |
38 | 38 | ||
39 | def runCommand(self, cmd): | 39 | def runCommand(self, cmd, **kwargs): |
40 | failing = kwargs.get('failing', False) | ||
40 | cmd_args = [CASPER_EXEC, '--no-colors'] + cmd.split(' ') | 41 | cmd_args = [CASPER_EXEC, '--no-colors'] + cmd.split(' ') |
41 | try: | 42 | try: |
42 | return subprocess.check_output(cmd_args).strip() | 43 | return subprocess.check_output(cmd_args).strip() |
44 | if failing: | ||
45 | raise AssertionError('Command %s has not failed' % cmd) | ||
43 | except subprocess.CalledProcessError as err: | 46 | except subprocess.CalledProcessError as err: |
44 | raise IOError('Command %s exited with status %s' % (cmd, err.status)) | 47 | if failing: |
48 | return err.output | ||
49 | else: | ||
50 | raise IOError('Command %s exited with status %s' | ||
51 | % (cmd, err.errorcode)) | ||
45 | 52 | ||
46 | def assertCommandOutputEquals(self, cmd, result): | 53 | def assertCommandOutputEquals(self, cmd, result, **kwargs): |
47 | self.assertEquals(self.runCommand(cmd), result) | 54 | self.assertEquals(self.runCommand(cmd), result) |
48 | 55 | ||
49 | def assertCommandOutputContains(self, cmd, what): | 56 | def assertCommandOutputContains(self, cmd, what, **kwargs): |
50 | if isinstance(what, (list, tuple)): | 57 | if isinstance(what, (list, tuple)): |
51 | for entry in what: | 58 | for entry in what: |
52 | self.assertIn(entry, self.runCommand(cmd)) | 59 | self.assertIn(entry, self.runCommand(cmd, **kwargs)) |
53 | else: | 60 | else: |
54 | self.assertIn(what, self.runCommand(cmd)) | 61 | self.assertIn(what, self.runCommand(cmd)) |
55 | 62 | ||
... | @@ -97,5 +104,22 @@ class CasperExecTest(unittest.TestCase): | ... | @@ -97,5 +104,22 @@ class CasperExecTest(unittest.TestCase): |
97 | '0 failed', | 104 | '0 failed', |
98 | ]) | 105 | ]) |
99 | 106 | ||
107 | @timeout(20) | ||
108 | def test_new_failing_test(self): | ||
109 | # using begin() | ||
110 | script_path = os.path.join(TEST_ROOT, 'tester', 'failing.js') | ||
111 | self.assertCommandOutputContains('test ' + script_path, [ | ||
112 | script_path, | ||
113 | '# true', | ||
114 | 'FAIL Subject is strictly true', | ||
115 | '# type: assert', | ||
116 | '# file: %s:3' % script_path, | ||
117 | '# code: test.assert(false);', | ||
118 | '# subject: false', | ||
119 | 'FAIL 1 tests executed', | ||
120 | '0 passed', | ||
121 | '1 failed.', | ||
122 | ], failing=True) | ||
123 | |||
100 | if __name__ == '__main__': | 124 | if __name__ == '__main__': |
101 | unittest.main() | 125 | unittest.main() | ... | ... |
-
Please register or sign in to post a comment