Exemplo n.º 1
0
    def test_wrap_raises(self):
        def x():
            raise NotImplementedError()

        config = Config()
        config.stop_on_first_failure = True
        f = []
        with self.assertRaises(NotImplementedError):
            wrap(config, f, None, x)
Exemplo n.º 2
0
    def test_wrap_wraps(self):
        def x():
            raise NotImplementedError()

        config = Config()
        config.stop_on_first_failure = False
        f = []
        default = object()  # value to return on failure
        result = wrap(config, f, None, x, default)

        self.assertIs(result, default)
        self.assertEqual(len(f), 1)
        self.assertIsNone(f[0][0])
        self.assertIn("Traceback", f[0][1])
Exemplo n.º 3
0
    def test_read(self):
        with open(self.tmp_fp, "w", encoding="utf8") as fh:
            fh.write(self.text)

        config = Config()
        config.stop_on_first_failure = True
        config.input_glob = self.tmp_fp
        config.output_dir = self.tmpdir.name

        examples, paths, failures = workflow.run(config)

        with self.subTest(part="found the file"):
            self.assertEqual([self.tmp_fp], paths)

        with self.subTest(part="no failures"):
            self.assertEqual([], failures)

        with self.subTest(part="one example extracted"):
            self.assertEqual(len(examples), self.expect_examples)

        for k, v in examples.items():
            with self.subTest(part="example matches"):
                self.assertEqual("\n".join(v), P.sample_output)
                self.assertIn(self.example_name, k[-1])