예제 #1
0
    def test_with_code_indent(self):
        with open(self.output_file_path, "w", newline="\n") as f:
            writer = CodeWriter()

            writer.addln("import module_1")
            writer.new_line(2)
            writer.addln("def add(x1, x2):")
            with CodeWriterIndent(1):
                writer.addln("pass")
            writer.new_line(2)
            writer.addln("f: float = 0.5")

            writer.format(style_config="pep8")
            writer.write(f)

        expect_file_path = "{}/{}".format(self.data_dir, "code_writer_test_with_code_indent.py")
        actual_file_path = self.output_file_path
        with open(actual_file_path, "r") as f:
            self.log(f.read())
        self.assertTrue(filecmp.cmp(expect_file_path, actual_file_path))
예제 #2
0
    def test_normal(self):
        with open(self.output_file_path, "w", newline="\n") as f:
            writer = CodeWriter()

            writer.addln("import module_1")
            writer.new_line(2)
            writer.addln("i: int = 10")

            writer.format(style_config="pep8")
            writer.write(f)

        expect_file_path = "{}/{}".format(self.data_dir, "code_writer_test_normal.py")
        actual_file_path = self.output_file_path
        with open(actual_file_path, "r") as f:
            self.log(f.read())
        self.assertTrue(filecmp.cmp(expect_file_path, actual_file_path))