示例#1
0
    def test_header_row_in_csv_output(self):
        expected_header = (
            'about_file,name,version,about_resource,'
            'spec_version,date,description,description_file,'
            'home_url,download_url,readme,readme_file,install,install_file,'
            'changelog,changelog_file,news,news_file,news_url,notes,notes_file,'
            'contact,owner,author,author_file,copyright,copyright_file,'
            'notice_file,notice_url,license_text_file,license_url,license_spdx,'
            'redistribute,attribute,track_changes,vcs_tool,vcs_repository,'
            'vcs_path,vcs_tag,vcs_branch,vcs_revision,checksum_sha1,checksum_md5,'
            'checksum_sha256,dje_component,dje_license_key,dje_organization,'
            'dje_license_name,scm_branch,scm_repository,signature_gpg_file,'
            'redistribute_sources,dje_license,about_format,usage,'
            'license_text,notice,scm_path,scm_tool,scm_rev,scm_tag,organization,'
            'warnings,errors'
        )

        test_file = 'about_code_tool/tests/testdata/basic'
        output = get_temp_file()
        collector = Collector(test_file)
        collector.write_to_csv(output)
        with open(output) as f:
            header_row = f.readline().replace('\n', '').replace('\r', '')
        header_row_array = header_row.split(',')
        expected_header_array = expected_header.split(',')
        self.assertEqual(len(expected_header_array), len(header_row_array))
        for key in header_row_array:
            self.assertTrue(key in expected_header_array)
示例#2
0
 def test_generate_attribution_with_limit_to(self):
     f = open(join(TESTDATA_DIR, 'attrib/attrib.html'))
     expected = f.read()
     test_file = join(TESTDATA_DIR, 'attrib/')
     collector = Collector(test_file)
     result = collector.generate_attribution(limit_to=['/attrib.ABOUT'])
     # Strip all the white spaces
     self.assertEqual(re.sub(r'\s+', '', expected), re.sub(r'\s+', '', result))
示例#3
0
 def test_generate_attribution_verification(self):
     expected = (u'name,version,copyright,dje_license_name\n'
                 u'Apache HTTP Server,2.4.3,,')
     test_file = join(TESTDATA_DIR, 'attrib/attrib.ABOUT')
     collector = Collector(test_file)
     test_path = get_temp_file('test.csv')
     collector.generate_attribution(limit_to=[''], verification=test_path)
     with open(test_path, 'rU') as f:
         self.assertEqual(f.read().rstrip(), expected)
示例#4
0
 def test_generate_attribution_with_custom_template(self):
     expected = (u'notice_text:'
                 u'version:2.4.3'
                 u'about_resource:httpd-2.4.3.tar.gz'
                 u'name:Apache HTTP Serverlicense_text:')
     test_file = join(TESTDATA_DIR, 'attrib/attrib.ABOUT')
     collector = Collector(test_file)
     template = join(TESTDATA_DIR, 'attrib/test.template')
     result = collector.generate_attribution(template, limit_to=[''])
     self.assertEqual(expected, result)
示例#5
0
 def test_return_path_is_not_abspath_and_contains_subdirs_on_dir(self):
     # Using a relative path for the purpose of this test
     test_file = 'about_code_tool/tests/testdata/basic'
     output = get_temp_file()
     collector = Collector(test_file)
     collector.write_to_csv(output)
     expected = '/basic'
     # FIXME: why [2]? what this test means?
     # CY: Since the output is going to have 2 rows (header row and row with
     # the test file data), the below partition('\n')[2] means to only read
     # the data row and ignroe the header row. This test is to make sure 
     # the path in the data row is not an absolute path.
     with open(output) as f:
         self.assertTrue(f.read().partition('\n')[2].startswith(expected))
示例#6
0
 def test_collect_can_collect_a_single_file(self):
     test_file = ('about_code_tool/tests/testdata/thirdparty/django_snippets_2413.ABOUT')
     if on_windows:
         expected = [posix_path(UNC_PREFIX + os.path.abspath('about_code_tool/tests/testdata/thirdparty/django_snippets_2413.ABOUT'))]
     else:
         expected = [os.path.abspath('about_code_tool/tests/testdata/thirdparty/django_snippets_2413.ABOUT')]
     result = Collector.collect(test_file)
     self.assertEqual(expected, result)
示例#7
0
 def test_collect_can_collect_a_directory_tree(self):
     test_dir = 'about_code_tool/tests/testdata/DateTest'
     if on_windows:
         expected = [
             (posix_path(UNC_PREFIX + os.path.abspath('about_code_tool/tests/testdata/DateTest/non-supported_date_format.ABOUT'))),
             (posix_path(UNC_PREFIX + os.path.abspath('about_code_tool/tests/testdata/DateTest/supported_date_format.ABOUT')))
         ]
     else:
         expected = [
             (os.path.abspath('about_code_tool/tests/testdata/DateTest/non-supported_date_format.ABOUT')),
             (os.path.abspath('about_code_tool/tests/testdata/DateTest/supported_date_format.ABOUT'))
         ]
     result = Collector.collect(test_dir)
     self.assertEqual(sorted(expected), sorted(result))
示例#8
0
    def test_collect_can_collect_a_directory_tree_with_long_and_deep_paths(self):
        test_zip = 'about_code_tool/tests/testdata/longpath/longpath.zip'
        test_dir = extract_zip(test_zip)


        longpath = 'longpath1/' * 28
        expected = 'longpath/' + longpath + 'non-supported_date_format.ABOUT'

        result = Collector.collect(test_dir)[0]
        def rel_path(pth):
            p = posix_path(pth)
            return p.partition('/longpath/')[2]
        print()
        print(result)
        print(rel_path(result))
        self.assertEqual(expected, rel_path(result))