示例#1
0
文件: test_run.py 项目: sembug/choosy
    def test_error(self):
        class MyException(Exception):
            pass

        c = Checker()
        with self.assertRaises(MyException):
            with c.expect("Everything will be fine"):
                raise MyException("It wasn't fine!")
        self.assertEqual(self.clean_results(c.results), [
            {
                'status': 'ERROR',
                'expect': "Everything will be fine",
                'did': "It wasn't fine!",
                'exception': {
                    'type':
                    "MyException",
                    'message':
                    "It wasn't fine!",
                    'readable':
                    "MyException: It wasn't fine!",
                    'traceback': [
                        {
                            'file': 'checker/tests/test_run.py',
                            'line': 0,
                            'function': 'test_error',
                            'text': 'raise MyException("It wasn\'t fine!")'
                        },
                    ]
                },
            },
        ])
示例#2
0
文件: test_run.py 项目: nedbat/choosy
 def test_quiet_expects(self):
     c = Checker()
     with c.expect("It isn't even worth mentioning.", quiet=True):
         pass
     with c.expect("Let's talk about this."):
         pass
     self.assertEqual(c.results, [{"status": "OK", "expect": "Let's talk about this."}])
示例#3
0
文件: test_run.py 项目: nedbat/choosy
    def test_error(self):
        class MyException(Exception):
            pass

        c = Checker()
        with self.assertRaises(MyException):
            with c.expect("Everything will be fine"):
                raise MyException("It wasn't fine!")
        self.assertEqual(
            self.clean_results(c.results),
            [
                {
                    "status": "ERROR",
                    "expect": "Everything will be fine",
                    "did": "It wasn't fine!",
                    "exception": {
                        "type": "MyException",
                        "message": "It wasn't fine!",
                        "readable": "MyException: It wasn't fine!",
                        "traceback": [
                            {
                                "file": "checker/tests/test_run.py",
                                "line": 0,
                                "function": "test_error",
                                "text": 'raise MyException("It wasn\'t fine!")',
                            }
                        ],
                    },
                }
            ],
        )
示例#4
0
文件: test_run.py 项目: nedbat/choosy
 def test_flaky_function(self):
     c = Checker()
     c.function_returns(self, "flaky", [(2, 2), (3, 3), (4, 4)])
     self.assertEqual(
         self.clean_results(c.results),
         [
             {"status": "OK", "expect": "flaky(2) should return 2."},
             {
                 "status": "ERROR",
                 "expect": "flaky(3) should return 3.",
                 "did": "Oops",
                 "exception": {
                     "type": "Flake",
                     "message": "Oops",
                     "readable": "Flake: Oops",
                     "traceback": [
                         {
                             "file": "checker/exerciser.py",
                             "line": 0,
                             "function": "function_returns",
                             "text": "actual_output = fn(*inputs)",
                         },
                         {
                             "file": "checker/tests/test_run.py",
                             "line": 0,
                             "function": "flaky",
                             "text": 'raise self.Flake("Oops")',
                         },
                     ],
                 },
             },
             {"status": "OK", "expect": "flaky(4) should return 4."},
         ],
     )
示例#5
0
文件: test_run.py 项目: nedbat/choosy
 def test_success(self):
     c = Checker()
     try:
         with c.expect("This should work"):
             pass
     except Checker.Done:  # pragma: nocover
         self.fail("Shouldn't have raised Done here.")
     self.assertEqual(c.results, [{"status": "OK", "expect": "This should work"}])
示例#6
0
文件: test_run.py 项目: sembug/choosy
 def test_no_such_function(self):
     c = Checker()
     with self.assertRaises(Checker.Done):
         c.function_returns(self, 'nothing', [(1, 2), (2, 4)])
     self.assertEqual(c.results, [
         {
             'status': 'FAIL',
             'expect': 'You should have a function named nothing.'
         },
     ])
示例#7
0
文件: test_run.py 项目: nedbat/choosy
 def test_failure(self):
     c = Checker()
     try:
         with c.expect("This should work"):
             c.fail("It failed!")
             self.fail("We shouldn't have run past a c.fail")  # pragma: nocover
         self.fail("We shouldn't have continued after a failed c.should")  # pragma: nocover
     except Checker.Done:
         pass
     self.assertEqual(c.results, [{"status": "FAIL", "expect": "This should work", "did": "It failed!"}])
示例#8
0
文件: test_run.py 项目: nedbat/choosy
 def test_simple(self):
     c = Checker()
     c.function_returns(self, "simple", [(1, 2), (2, 4)])
     self.assertEqual(
         c.results,
         [
             {"status": "OK", "expect": "simple(1) should return 2."},
             {"status": "OK", "expect": "simple(2) should return 4."},
         ],
     )
示例#9
0
文件: test_run.py 项目: sembug/choosy
 def test_not_callable(self):
     c = Checker()
     self.mylist = []
     with self.assertRaises(Checker.Done):
         c.function_returns(self, 'mylist', [(1, 2), (2, 4)])
     self.assertEqual(c.results, [
         {
             'status': 'FAIL',
             'expect': 'You should have a function named mylist.'
         },
     ])
示例#10
0
文件: test_run.py 项目: nedbat/choosy
 def test_multiple_arguments(self):
     c = Checker()
     c.function_returns(self, "add3", [(1, 2, 3, 6), (1, 1, 1, 3), (10, 11, 12, 33)])
     self.assertEqual(
         c.results,
         [
             {"status": "OK", "expect": "add3(1, 2, 3) should return 6."},
             {"status": "OK", "expect": "add3(1, 1, 1) should return 3."},
             {"status": "OK", "expect": "add3(10, 11, 12) should return 33."},
         ],
     )
示例#11
0
文件: test_run.py 项目: nedbat/choosy
 def test_wrong_answers(self):
     c = Checker()
     c.function_returns(self, "simple", [(1, 2), (2, 17), (3, 6)])
     self.assertEqual(
         c.results,
         [
             {"status": "OK", "expect": "simple(1) should return 2."},
             {"status": "FAIL", "expect": "simple(2) should return 17.", "did": "You returned 4."},
             {"status": "OK", "expect": "simple(3) should return 6."},
         ],
     )
示例#12
0
文件: test_run.py 项目: sembug/choosy
 def test_quiet_expects(self):
     c = Checker()
     with c.expect("It isn't even worth mentioning.", quiet=True):
         pass
     with c.expect("Let's talk about this."):
         pass
     self.assertEqual(c.results, [
         {
             'status': 'OK',
             'expect': "Let's talk about this."
         },
     ])
示例#13
0
文件: test_run.py 项目: sembug/choosy
 def test_simple(self):
     c = Checker()
     c.function_returns(self, 'simple', [(1, 2), (2, 4)])
     self.assertEqual(c.results, [
         {
             'status': 'OK',
             'expect': 'simple(1) should return 2.'
         },
         {
             'status': 'OK',
             'expect': 'simple(2) should return 4.'
         },
     ])
示例#14
0
文件: test_run.py 项目: sembug/choosy
 def test_success(self):
     c = Checker()
     try:
         with c.expect("This should work"):
             pass
     except Checker.Done:  # pragma: nocover
         self.fail("Shouldn't have raised Done here.")
     self.assertEqual(c.results, [
         {
             'status': 'OK',
             'expect': "This should work"
         },
     ])
示例#15
0
文件: test_run.py 项目: nedbat/choosy
 def test_failure_with_continue_on_fail(self):
     c = Checker()
     try:
         with c.expect("This should work", continue_on_fail=True):
             c.fail("It failed!")
             self.fail("We shouldn't have run past a c.fail")  # pragma: nocover
         with c.expect("Also this one"):
             pass
     except Checker.Done:  # pragma: nocover
         self.fail("Shouldn't have raised Done here.")
     self.assertEqual(
         c.results,
         [
             {"status": "FAIL", "expect": "This should work", "did": "It failed!"},
             {"status": "OK", "expect": "Also this one"},
         ],
     )
示例#16
0
文件: test_run.py 项目: sembug/choosy
 def test_failure(self):
     c = Checker()
     try:
         with c.expect("This should work"):
             c.fail("It failed!")
             self.fail(
                 "We shouldn't have run past a c.fail")  # pragma: nocover
         self.fail("We shouldn't have continued after a failed c.should"
                   )  # pragma: nocover
     except Checker.Done:
         pass
     self.assertEqual(c.results, [
         {
             'status': 'FAIL',
             'expect': "This should work",
             'did': "It failed!"
         },
     ])
示例#17
0
文件: test_run.py 项目: sembug/choosy
 def test_multiple_arguments(self):
     c = Checker()
     c.function_returns(self, 'add3', [(1, 2, 3, 6), (1, 1, 1, 3),
                                       (10, 11, 12, 33)])
     self.assertEqual(c.results, [
         {
             'status': 'OK',
             'expect': 'add3(1, 2, 3) should return 6.'
         },
         {
             'status': 'OK',
             'expect': 'add3(1, 1, 1) should return 3.'
         },
         {
             'status': 'OK',
             'expect': 'add3(10, 11, 12) should return 33.'
         },
     ])
示例#18
0
文件: test_run.py 项目: sembug/choosy
 def test_wrong_answers(self):
     c = Checker()
     c.function_returns(self, 'simple', [(1, 2), (2, 17), (3, 6)])
     self.assertEqual(c.results, [
         {
             'status': 'OK',
             'expect': 'simple(1) should return 2.'
         },
         {
             'status': 'FAIL',
             'expect': 'simple(2) should return 17.',
             'did': 'You returned 4.'
         },
         {
             'status': 'OK',
             'expect': 'simple(3) should return 6.'
         },
     ])
示例#19
0
文件: test_run.py 项目: sembug/choosy
 def test_flaky_function(self):
     c = Checker()
     c.function_returns(self, 'flaky', [(2, 2), (3, 3), (4, 4)])
     self.assertEqual(self.clean_results(c.results), [
         {
             'status': 'OK',
             'expect': 'flaky(2) should return 2.'
         },
         {
             'status': 'ERROR',
             'expect': "flaky(3) should return 3.",
             'did': 'Oops',
             'exception': {
                 'type':
                 'Flake',
                 'message':
                 'Oops',
                 'readable':
                 'Flake: Oops',
                 'traceback': [
                     {
                         'file': 'checker/exerciser.py',
                         'line': 0,
                         'function': 'function_returns',
                         'text': 'actual_output = fn(*inputs)'
                     },
                     {
                         'file': 'checker/tests/test_run.py',
                         'line': 0,
                         'function': 'flaky',
                         'text': 'raise self.Flake("Oops")'
                     },
                 ]
             },
         },
         {
             'status': 'OK',
             'expect': 'flaky(4) should return 4.'
         },
     ])
示例#20
0
文件: test_run.py 项目: nedbat/choosy
 def test_test(self):
     c = Checker()
     try:
         with c.expect("This should definitely work"):
             c.test(True, "This one was ok")
             c.test(False, "Oops, this was bad")
             raise Exception("Shouldn't have gotten to here")  # pragma: nocover
     except Checker.Done:
         pass
     self.assertEqual(
         c.results, [{"status": "FAIL", "expect": "This should definitely work", "did": "Oops, this was bad"}]
     )
示例#21
0
文件: test_run.py 项目: sembug/choosy
 def test_test(self):
     c = Checker()
     try:
         with c.expect("This should definitely work"):
             c.test(True, "This one was ok")
             c.test(False, "Oops, this was bad")
             raise Exception(
                 "Shouldn't have gotten to here")  # pragma: nocover
     except Checker.Done:
         pass
     self.assertEqual(c.results, [
         {
             'status': 'FAIL',
             'expect': "This should definitely work",
             'did': "Oops, this was bad"
         },
     ])
示例#22
0
文件: test_run.py 项目: sembug/choosy
 def test_failure_with_continue_on_fail(self):
     c = Checker()
     try:
         with c.expect("This should work", continue_on_fail=True):
             c.fail("It failed!")
             self.fail(
                 "We shouldn't have run past a c.fail")  # pragma: nocover
         with c.expect("Also this one"):
             pass
     except Checker.Done:  # pragma: nocover
         self.fail("Shouldn't have raised Done here.")
     self.assertEqual(c.results, [
         {
             'status': 'FAIL',
             'expect': "This should work",
             'did': "It failed!"
         },
         {
             'status': 'OK',
             'expect': "Also this one"
         },
     ])
示例#23
0
文件: test_run.py 项目: nedbat/choosy
 def test_no_such_function(self):
     c = Checker()
     with self.assertRaises(Checker.Done):
         c.function_returns(self, "nothing", [(1, 2), (2, 4)])
     self.assertEqual(c.results, [{"status": "FAIL", "expect": "You should have a function named nothing."}])
示例#24
0
文件: test_run.py 项目: nedbat/choosy
 def test_not_callable(self):
     c = Checker()
     self.mylist = []
     with self.assertRaises(Checker.Done):
         c.function_returns(self, "mylist", [(1, 2), (2, 4)])
     self.assertEqual(c.results, [{"status": "FAIL", "expect": "You should have a function named mylist."}])