def test_success(self): orig_lint_fn = lint_test_expectations.lint # unused args pylint: disable=W0613 def interrupting_lint(host, options, logging_stream): raise KeyboardInterrupt def successful_lint(host, options, logging_stream): return 0 def exception_raising_lint(host, options, logging_stream): assert False stdout = StringIO.StringIO() stderr = StringIO.StringIO() try: lint_test_expectations.lint = interrupting_lint res = lint_test_expectations.main([], stdout, stderr) self.assertEqual(res, lint_test_expectations.INTERRUPTED_EXIT_STATUS) lint_test_expectations.lint = successful_lint res = lint_test_expectations.main(['--platform', 'test'], stdout, stderr) self.assertEqual(res, 0) lint_test_expectations.lint = exception_raising_lint res = lint_test_expectations.main([], stdout, stderr) self.assertEqual(res, lint_test_expectations.EXCEPTIONAL_EXIT_STATUS) finally: lint_test_expectations.lint = orig_lint_fn
def test_interrupt(self): def interrupting_lint(host, options): raise KeyboardInterrupt lint_test_expectations.lint = interrupting_lint res = lint_test_expectations.main([], self.stdout, self.stderr) self.assertEqual(res, lint_test_expectations.INTERRUPTED_EXIT_STATUS)
def test_exception(self): def exception_raising_lint(host, options): assert False lint_test_expectations.lint = exception_raising_lint res = lint_test_expectations.main([], self.stdout, self.stderr) self.assertEqual(res, lint_test_expectations.EXCEPTIONAL_EXIT_STATUS)
def test_exception(self): def exception_raising_lint(host, options): # pylint: disable=unused-argument assert False lint_test_expectations.lint = exception_raising_lint res = lint_test_expectations.main([], self.stderr, host=MockHost()) self.assertEqual(res, exit_codes.EXCEPTIONAL_EXIT_STATUS)
def test_interrupt(self): def interrupting_lint(host, options): # pylint: disable=unused-argument raise KeyboardInterrupt lint_test_expectations.lint = interrupting_lint res = lint_test_expectations.main([], self.stderr, host=MockHost()) self.assertEqual(res, exit_codes.INTERRUPTED_EXIT_STATUS)
def test_failure(self): lint_test_expectations.lint = lambda host, options: True res = lint_test_expectations.main(['--platform', 'test'], self.stdout, self.stderr) self.assertTrue('Lint failed' in self.stderr.getvalue()) self.assertEqual(res, 1)
def test_success(self): lint_test_expectations.lint = lambda host, options: False res = lint_test_expectations.main(['--platform', 'test'], self.stdout, self.stderr) self.assertTrue('Lint succeeded' in self.stderr.getvalue()) self.assertEqual(res, 0)
def test_failure(self): lint_test_expectations.lint = lambda host, options: ["test failure"] res = lint_test_expectations.main(["--platform", "test"], self.stdout, self.stderr) self.assertTrue("Lint failed" in self.stderr.getvalue()) self.assertEqual(res, 1)
def test_success(self): lint_test_expectations.lint = lambda host, options: [] res = lint_test_expectations.main(["--platform", "test"], self.stdout, self.stderr) self.assertTrue("Lint succeeded" in self.stderr.getvalue()) self.assertEqual(res, 0)