def test_license_text_extracted_from_license_text_file(self): expected = '''Tester holds the copyright for test component. Tester relinquishes copyright of this software and releases the component to Public Domain. * Email [email protected] for any questions''' test_file = join(TESTDATA_DIR, 'attrib/license_text.ABOUT') about_file = AboutFile(test_file) result = about_file.license_text() self.assertEqual(expected, result)
def test_get_custom_field_keys(self): about_file = AboutFile(join(TESTDATA_DIR, 'basic/basic.about')) result = about_file.get_custom_field_keys() expected = [ 'scm_branch', 'scm_repository', 'signature_gpg_file', 'redistribute_sources', 'dje_license', 'about_format', 'usage', # These two keys are removed from the spec and therefore # become a custom keys 'license_text', 'notice', 'scm_path', 'scm_tool', 'scm_rev', 'scm_tag', 'organization' ] self.assertEqual(result, expected)
def test_user_forget_space_for_continuation_line(self): text_input = ''' about_resource: jquery.js name: jQuery version: 1.2.3 notes: this is the first line. this is the second. this is the third. date: 2013-01-02 ''' expected = '''about_resource: jquery.js name: jQuery version: 1.2.3 notes: this is the first line. date: 2013-01-02 ''' expected_warnings = [(IGNORED, 'this is the second.\n'), (IGNORED, ' this is the third.\n')] about_obj = AboutFile() result, warn = AboutFile.pre_process(about_obj, StringIO(text_input)) self.assertEqual(expected, result.read()) for i, w in enumerate(warn): self.assertEqual(expected_warnings[i][0], w.code) self.assertEqual(expected_warnings[i][1], w.field_value)
def test_pre_process_with_spaces_left_of_colon(self): text_input = ''' about_resource : jquery.js name: jQuery version: 1.2.3 ''' expected = '''about_resource: jquery.js name: jQuery version: 1.2.3 ''' about_obj = AboutFile() result, _warn = AboutFile.pre_process(about_obj, StringIO(text_input)) self.assertEqual(expected, result.read())
def test_pre_process_with_invalid_chars_in_field_name(self): text_input = ''' about_resource: jquery.js name: jQuery vers|ion: 1.2.3 ''' expected = '''about_resource: jquery.js name: jQuery ''' about_obj = AboutFile() result, warn = AboutFile.pre_process(about_obj, StringIO(text_input)) self.assertEqual(IGNORED, warn[0].code) self.assertEqual('vers|ion', warn[0].field_name) self.assertEqual(expected, result.read())
def test_remove_blank_lines_and_field_spaces(self): text_input = ''' name: test space version: 0.7.0 about_resource: about.py field with spaces: This is a test case for field with spaces ''' expected = '''name: test space version: 0.7.0 about_resource: about.py ''' msg = 'field with spaces: This is a test case for field with spaces\n' expected_warnings = [(IGNORED, msg)] about_obj = AboutFile() result, warn = AboutFile.pre_process(about_obj, StringIO(text_input)) self.assertEqual(expected, result.read()) for i, w in enumerate(warn): self.assertEqual(expected_warnings[i][0], w.code) self.assertEqual(expected_warnings[i][1], w.field_value)
def test_remove_blank_lines_and_no_colon_fields(self): text_input = ''' name: no colon test test version: 0.7.0 about_resource: about.py test with no colon ''' expected = '''name: no colon test version: 0.7.0 about_resource: about.py ''' expected_warnings = [(IGNORED, 'test\n'), (IGNORED, 'test with no colon\n')] about_obj = AboutFile() result, warn = AboutFile.pre_process(about_obj, StringIO(text_input)) self.assertEqual(expected, result.read()) for i, w in enumerate(warn): self.assertEqual(expected_warnings[i][0], w.code) self.assertEqual(expected_warnings[i][1], w.field_value)
def test_check_url__without_network__not_ends_with_com(self): about_file = AboutFile() self.assertTrue(about_file.check_url('http://www.google', False))
def test_check_url__without_network__no_schemes(self): about_file = AboutFile() self.assertFalse(about_file.check_url('google.com', False)) self.assertFalse(about_file.check_url('www.google.com', False)) self.assertFalse(about_file.check_url('', False))
def test_result_chars_in_file_name(self): about_obj = AboutFile() result = about_obj.invalid_chars_in_about_file_name('_$a+s/afg:') expected = [':'] self.assertEqual(expected, result)
def test_get_about_name(self): about_file = AboutFile(join(TESTDATA_DIR, 'basic/simple.about')) result = about_file.get_about_name() self.assertEqual(result, 'simple')
def test_result_chars_in_file_name_path2(self): about_obj = AboutFile() name = '%6571351()275612$_$asafg:' result = about_obj.invalid_chars_in_about_file_name(name) expected = ['%', '(', ')', '$', '$', ':'] self.assertEqual(expected, result)
def test_validate_is_ascii_key(self): about_file = AboutFile() self.assertTrue(about_file.check_is_ascii('abc')) self.assertTrue(about_file.check_is_ascii('123')) self.assertTrue(about_file.check_is_ascii('!!!')) self.assertFalse(about_file.check_is_ascii(u'測試'))
def test_handles_last_line_is_not_a_continuation_line(self): warnings = [] warn = AboutFile.check_line_continuation(' Last line is NOT a continuation line.', False) warnings.append(warn) self.assertEqual(1, len(warnings))
def test_handles_last_line_is_a_continuation_line(self): warnings = [] warn = AboutFile.check_line_continuation(' Last line is a continuation line.', True) warnings.append(warn) self.assertEqual(warnings, [''])
def test_result_space_in_file_name(self): about_obj = AboutFile() result = about_obj.invalid_chars_in_about_file_name('_ Hello') expected = [' '] self.assertEqual(expected, result)
def test_check_url__without_network__ends_with_slash(self): about_file = AboutFile() self.assertTrue(about_file.check_url('http://www.google.co.uk/', False))
def test_check_url__without_network__empty_URL(self): about_file = AboutFile() self.assertFalse(about_file.check_url('http:', False))
def test_check_url__with_network(self): about_file = AboutFile() self.assertTrue(about_file.check_url('http://www.google.com', True)) self.assertTrue(about_file.check_url('http://www.google.co.uk/', True))
def test_notice_text_extacted_from_notice_text_file(self): expected = '''Test component is released to Public Domain.''' test_file = join(TESTDATA_DIR, 'attrib/license_text.ABOUT') about_file = AboutFile(test_file) result = about_file.notice_text() self.assertEqual(result, expected)
def test_notice_text_returns_empty_string_when_ref_file_doesnt_exist(self): expected = '' test_file = join(TESTDATA_DIR, 'attrib/missing_notice_license_files.ABOUT') about_file = AboutFile(test_file) result = about_file.notice_text() self.assertEqual(result, expected)
def test_check_url__with_network__not_starting_with_www(self): about_file = AboutFile() self.assertTrue(about_file.check_url('https://nexb.com', True)) self.assertTrue(about_file.check_url('http://archive.apache.org/dist/httpcomponents/commons-httpclient/2.0/source/commons-httpclient-2.0-alpha2-src.tar.gz', True)) if check_network_connection(): self.assertFalse(about_file.check_url('http://nothing_here.com', True))
def test_result_chars_in_file_name_path(self): about_obj = AboutFile() name = '%6571351()275612$/_$asafg:/' result = about_obj.invalid_chars_in_about_file_name(name) expected = [] self.assertEqual(expected, result)
def test_notice_text_returns_empty_string_when_no_field_present(self): test_file = join(TESTDATA_DIR, 'attrib/no_text_file_field.ABOUT') about_file = AboutFile(test_file) result = about_file.notice_text() expected = '' self.assertEqual(result, expected)
def test_check_url__with_network__not_starting_with_www_and_spaces(self): # TODO: this does work yet as we do not have a solution for now (URL with spaces) about_file = AboutFile() self.assertTrue(about_file.check_url(u'http://de.wikipedia.org/wiki/Elf (Begriffsklärung)', True))
def test_check_url__with_network__not_reachable(self): about_file = AboutFile() if check_network_connection(): self.assertFalse(about_file.check_url('http://www.google', True))
def test_check_url__without_network__not_starting_with_www(self): about_file = AboutFile() self.assertTrue(about_file.check_url('https://nexb.com', False)) self.assertTrue(about_file.check_url('http://archive.apache.org/dist/httpcomponents/commons-httpclient/2.0/source/commons-httpclient-2.0-alpha2-src.tar.gz', False)) self.assertTrue(about_file.check_url('http://de.wikipedia.org/wiki/Elf (Begriffsklärung)', False)) self.assertTrue(about_file.check_url('http://nothing_here.com', False))
def test_get_dje_license_name(self): about_file = AboutFile(join(TESTDATA_DIR, 'basic/simple.about')) result = about_file.get_dje_license_name() self.assertEqual(result, 'Apache License 2.0')
def test_valid_chars_in_file_name(self): about_obj = AboutFile() name = string.digits + string.ascii_letters + '_-.+' result = about_obj.invalid_chars_in_about_file_name(name) expected = [] self.assertEqual(expected, result)