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)
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")
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)
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
def test_can_use_chardet_for_encoding(self): command = Command() command.set_encodings('chardet') command.set_source_patterns(self.pygount_folder) command.execute()
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')
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')
def test_can_use_chardet_for_encoding(self): command = Command() command.set_encodings("chardet") command.set_source_patterns(_PYGOUNT_SOURCE_FOLDER) command.execute()
def test_can_set_encoding(self): command = Command() command.set_encodings("automatic;cp1252") assert command.default_encoding == "automatic" assert command.fallback_encoding == "cp1252"
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)