コード例 #1
0
ファイル: test_command.py プロジェクト: speijnik/pygount
 def test_fails_on_unknown_output_format(self):
     unknown_output_format = 'no_such_output_format'
     command = Command()
     self.assertRaisesRegex(
         OptionError,
         unknown_output_format,
         command.set_output_format,
         unknown_output_format)
コード例 #2
0
 def test_fails_on_broken_regex(self):
     command = Command()
     with pytest.raises(
             OptionError,
             match=
             r"^option --generated: cannot parse pattern for regular repression.*"
     ):
         command.set_generated_regexps("[regex](", "option --generated")
コード例 #3
0
ファイル: test_command.py プロジェクト: speijnik/pygount
 def test_can_execute_on_own_code(self):
     output_path = os.path.join(self.tests_temp_folder, 'test_can_execute_on_own_code.txt')
     try:
         os.remove(output_path)
     except FileNotFoundError:
         pass  # Ignore missing file as it is going to be recreated.
     command = Command()
     command.set_output(output_path)
     command.set_output_format('cloc-xml')
     command.set_source_patterns(self.pygount_folder)
     command.set_suffices('py')
     command.execute()
     cloc_xml_root = ElementTree.parse(output_path)
     file_elements = cloc_xml_root.findall('files/file')
     self.assertIsNotNone(file_elements)
     self.assertNotEqual(len(file_elements), 0)
コード例 #4
0
 def test_can_execute_on_own_code(self):
     output_path = os.path.join(self.tests_temp_folder,
                                "test_can_execute_on_own_code.txt")
     try:
         os.remove(output_path)
     except FileNotFoundError:
         pass  # Ignore missing file as it is going to be recreated.
     command = Command()
     command.set_output(output_path)
     command.set_output_format("cloc-xml")
     command.set_source_patterns(_PYGOUNT_SOURCE_FOLDER)
     command.set_suffixes("py")
     command.execute()
     cloc_xml_root = ElementTree.parse(output_path)
     file_elements = cloc_xml_root.findall("files/file")
     assert file_elements is not None
     assert len(file_elements) >= 1
コード例 #5
0
 def test_can_use_chardet_for_encoding(self):
     command = Command()
     command.set_encodings('chardet')
     command.set_source_patterns(self.pygount_folder)
     command.execute()
コード例 #6
0
 def test_fails_on_broken_regex(self):
     command = Command()
     self.assertRaisesRegex(
         OptionError,
         r'^option --generated: cannot parse pattern for regular repression.*',
         command.set_generated_regexps, '[regex](', 'option --generated')
コード例 #7
0
 def test_can_set_encoding(self):
     command = Command()
     command.set_encodings('automatic;cp1252')
     self.assertEqual(command.default_encoding, 'automatic')
     self.assertEqual(command.fallback_encoding, 'cp1252')
コード例 #8
0
 def test_can_use_chardet_for_encoding(self):
     command = Command()
     command.set_encodings("chardet")
     command.set_source_patterns(_PYGOUNT_SOURCE_FOLDER)
     command.execute()
コード例 #9
0
 def test_can_set_encoding(self):
     command = Command()
     command.set_encodings("automatic;cp1252")
     assert command.default_encoding == "automatic"
     assert command.fallback_encoding == "cp1252"
コード例 #10
0
 def test_fails_on_unknown_output_format(self):
     unknown_output_format = "no_such_output_format"
     command = Command()
     with pytest.raises(OptionError, match=unknown_output_format):
         command.set_output_format(unknown_output_format)