Esempio n. 1
0
    def test_print(self, mock_print):
        classes = ClassFactory.list(2)
        writer.register_format(self.FAKE_NAME, FakeGenerator())
        writer.print(classes, "fake")

        mock_print.assert_has_calls(
            [mock.call(obj.name, end="") for obj in classes])
Esempio n. 2
0
    def test_write_skip_empty_output(self):
        cls = ClassFactory.create()
        cls.name = ""
        with TemporaryDirectory() as tmpdir:
            writer.register_format(self.FAKE_NAME, FakeGenerator(tmpdir))
            writer.write([cls], "fake")

            self.assertFalse(Path(f"{tmpdir}/{cls.name}.txt").exists())
Esempio n. 3
0
    def test_write(self):
        classes = ClassFactory.list(2)
        with TemporaryDirectory() as tmpdir:
            writer.register_format(self.FAKE_NAME, FakeGenerator(tmpdir))
            writer.write(classes, "fake")

            for obj in classes:
                self.assertEqual(obj.name,
                                 Path(f"{tmpdir}/{obj.name}.txt").read_text())
Esempio n. 4
0
    def test_designate(self):
        classes = ClassFactory.list(3)
        classes[2].package = "foo!"
        classes[2].module = "tests!"

        writer.register_format(self.FAKE_NAME, FakeGenerator())
        writer.designate(classes, "fake")

        self.assertEqual("foo", classes[0].package)
        self.assertEqual("foo", classes[1].package)
        self.assertEqual("foo", classes[2].package)

        self.assertEqual("tests", classes[0].module)
        self.assertEqual("tests", classes[1].module)
        self.assertEqual("tests", classes[2].module)
Esempio n. 5
0
 def test_register_generator(self):
     writer.register_format(self.FAKE_NAME, FakeGenerator())
     self.assertIn("fake", writer.formats)
     self.assertIsInstance(writer.get_format("fake"), FakeGenerator)