コード例 #1
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."}])
コード例 #2
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."
         },
     ])
コード例 #3
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!")'
                        },
                    ]
                },
            },
        ])
コード例 #4
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!")',
                            }
                        ],
                    },
                }
            ],
        )
コード例 #5
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"},
         ],
     )
コード例 #6
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"}])
コード例 #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_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"}]
     )
コード例 #9
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"
         },
     ])
コード例 #10
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"
         },
     ])
コード例 #11
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"
         },
     ])
コード例 #12
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!"
         },
     ])