def test_get_displayable_summary(): from scancode.cli import get_displayable_summary from commoncode.resource import Codebase # Set up test codebase test_codebase = test_env.get_test_loc('summaries/client') codebase = Codebase(test_codebase, strip_root=True) codebase.timings['scan'] = 0 scan_names = 'foo, bar, baz' processes = 23 errors = ['failed to scan ABCD'] results = get_displayable_summary(codebase, scan_names, processes, errors) expected = ( [u'Some files failed to scan properly:', u'failed to scan ABCD'], [ u'Summary: foo, bar, baz with 23 process(es)', u'Errors count: 1', u'Scan Speed: 0.00 files/sec. ', u'Initial counts: 0 resource(s): 0 file(s) and 0 directorie(s) ', u'Final counts: 0 resource(s): 0 file(s) and 0 directorie(s) ', u'Timings:', u' scan_start: None', u' scan_end: None'] ) assert results == expected
def test_root_dir(self): test_file = self.get_test_loc('haxe/tags/haxelib.json') test_dir = self.get_test_loc('haxe/tags') codebase = Codebase(test_dir) manifest_resource = codebase.get_resource_from_path(test_file, absolute=True) proot = haxe.HaxePackage.get_package_root(manifest_resource, codebase) assert test_dir == proot.location
def test_BuckPackage_recognize_with_license(self): test_file = self.get_test_loc('buck/parse/license/BUCK') test_loc = self.get_test_loc('buck/parse/license/') result_package = list(build.BuckPackageHandler.parse(test_file))[0] codebase = Codebase(test_loc) resource = codebase.get_resource_from_path(test_file, absolute=True) license_expression = build.compute_normalized_license(result_package, resource, codebase) assert license_expression == 'apache-2.0'
def test_set_classification_flags_is_package_data_file(self): test_dir = self.get_test_loc('classify/manifest') codebase = Codebase( test_dir, resource_attributes=FileClassifier.resource_attributes) for res in codebase.walk(): if not res.is_file: continue set_classification_flags(res) assert res.is_manifest
def test_set_classification_flags_not_is_legal(self): test_dir = self.get_test_loc('classify/not-legal') codebase = Codebase( test_dir, resource_attributes=FileClassifier.resource_attributes) for res in codebase.walk(): if not res.is_file: continue set_classification_flags(res) assert not res.is_legal
def test_root_dir(self): test_file = self.get_test_loc( 'conda/requests-kerberos-0.8.0-py35_0.tar.bz2-extract/info/recipe.tar-extract/recipe/meta.yaml' ) test_dir = self.get_test_loc( 'conda/requests-kerberos-0.8.0-py35_0.tar.bz2-extract') codebase = Codebase(test_dir) resource = codebase.get_resource_from_path(test_file, absolute=True) proot = conda.CondaMetaYamlHandler.get_conda_root(resource, codebase) assert proot.location == test_dir
def test_package_root_is_properly_returned_for_metainf_poms(self): from packagedcode.plugin_package import PackageScanner test_dir = self.get_test_loc('maven_misc/package_root') codebase = Codebase(test_dir, resource_attributes=PackageScanner.resource_attributes) manifest_resource = [r for r in codebase.walk() if r.name == 'pom.xml'][0] packages = list(maven.MavenPomPackage.recognize(manifest_resource.location)) assert packages manifest_resource.packages.append(packages[0].to_dict()) manifest_resource.save(codebase) proot = maven.MavenPomPackage.get_package_root(manifest_resource, codebase) assert proot.name == 'activiti-image-generator-7-201802-EA-sources.jar-extract'
def test_root_dir(self): test_file = self.get_test_loc( 'conda/requests-kerberos-0.8.0-py35_0.tar.bz2-extract/info/recipe.tar-extract/recipe/meta.yaml' ) test_dir = self.get_test_loc( 'conda/requests-kerberos-0.8.0-py35_0.tar.bz2-extract') codebase = Codebase(test_dir) manifest_resource = codebase.get_resource_from_path(test_file, absolute=True) proot = conda.CondaPackage.get_package_root(manifest_resource, codebase) assert test_dir == proot.location
def test_ProcessIgnore_process_codebase_does_not_fail_to_access_an_ignored_resourced_cached_to_disk( self): test_dir = self.extract_test_tar('plugin_ignore/user.tgz') codebase = Codebase(test_dir, max_in_memory=1) test_plugin = ProcessIgnore() ignore = ['test'] test_plugin.process_codebase(codebase, ignore=ignore)
def test_npm_get_package_resources(self): test_loc = self.get_test_loc('npm/get_package_resources') codebase = Codebase(test_loc) root = codebase.root expected = [ 'get_package_resources', 'get_package_resources/package.json', 'get_package_resources/this-should-be-returned' ] results = [r.path for r in npm.NpmPackage.get_package_resources(root, codebase)] assert expected == results
def test_display_summary_edge_case_scan_time_zero_should_not_fail(): from io import StringIO import sys from scancode.cli import display_summary from commoncode.resource import Codebase # Set up test codebase test_codebase = test_env.get_test_loc('summaries/client') codebase = Codebase(test_codebase, strip_root=True) codebase.timings['scan'] = 0 scan_names = 'foo, bar, baz' processes = 23 errors = ['failed to scan ABCD'] try: # Redirect summary output from `stderr` to `result` result = StringIO() sys.stderr = result # Output from `display_summary` will be in `result` display_summary(codebase, scan_names, processes, errors) finally: # Set `stderr` back sys.stderr = sys.__stderr__
def test_build_get_package_resources(self): test_loc = self.get_test_loc('get_package_resources') codebase = Codebase(test_loc) root = codebase.root expected = [ 'get_package_resources', 'get_package_resources/BUCK', 'get_package_resources/file1', ] results = [ r.path for r in build.BaseBuildManifestPackage.get_package_resources( root, codebase) ] assert expected == results
def check_ProcessIgnore(self, test_dir, expected, ignore): codebase = Codebase(test_dir, strip_root=True) test_plugin = ProcessIgnore() test_plugin.process_codebase(codebase, ignore=ignore) resources = [res.path for res in codebase.walk(skip_root=True)] assert expected == sorted(resources)