def test_transforming_gofedlib_data(data, expected): """Test normalizing of gofedlib data.""" transformed_data = normalize(data) for key, value in expected.items(): assert key in transformed_data actual_value = transformed_data[key] if isinstance(actual_value, list): actual_value.sort() assert actual_value == value
def run_mercator(self, arguments, cache_path, outermost_only=True, timeout=600, resolve_poms=True): """Run mercator tool.""" # TODO: reduce cyclomatic complexity name = arguments.get('name') version = arguments.get('version') result_data = {'status': 'unknown', 'summary': [], 'details': []} mercator_target = arguments.get('cache_sources_path', cache_path) tc = TimedCommand(['mercator', mercator_target]) update_env = { 'MERCATOR_JAVA_RESOLVE_POMS': 'true' } if resolve_poms else {} status, data, err = tc.run(timeout=timeout, is_json=True, update_env=update_env) if status != 0: self.log.error(err) raise FatalTaskError(err) ecosystem_object = self.storage.get_ecosystem(arguments['ecosystem']) if ecosystem_object.is_backed_by(EcosystemBackend.pypi): # TODO: attempt static setup.py parsing with mercator items = [self._merge_python_items(mercator_target, data)] if items == [None]: raise NotABugFatalTaskError( 'Found no usable PKG-INFO/metadata.json/requirements.txt') else: if outermost_only: # process only root level manifests (or the ones closest to the root level) items = self.get_outermost_items(data.get('items') or []) else: items = data.get('items') or [] self.log.debug('mercator found %i projects, outermost %i', len(data), len(items)) if ecosystem_object.is_backed_by(EcosystemBackend.maven): # for maven we download both Jar and POM, we consider POM to be *the* # source of information and don't want to duplicate info by including # data from pom included in artifact (assuming it's included) items = [ d for d in items if d['ecosystem'].lower() == 'java-pom' ] elif ecosystem_object.is_backed_by(EcosystemBackend.npm): # ignore other metadata files, e.g. requirements.txt items = [d for d in items if d['ecosystem'].lower() == 'npm'] elif arguments['ecosystem'] == 'go': if not items: # Mercator found no Go Glide files, run gofedlib items = self.run_gofedlib(topdir=mercator_target, timeout=timeout) else: items = [ self._add_extra_go_fields(d, name, version) for d in items if d['ecosystem'].lower() in ('go-glide', 'go-godeps') ] result_data['details'] = [normalize(d) for d in items] result_data['status'] = 'success' return result_data
def test_transforming_godeps(): """Test normalizing of Godeps data.""" data = _load_json('go-godeps-from-mercator') expected = _load_json('go-godeps-expected') assert compare_dictionaries(normalize(data['items'][0]), expected)
def test_transforming_go_glide(): """Test normalizing of go glide (with locked deps) data.""" data = _load_json('go-glide-from-mercator') expected = _load_json('go-glide-expected') assert compare_dictionaries(normalize(data['items'][0]), expected)
def test_transforming_nuspec(): """Test normalizing of nuspec data.""" data = _load_json('nuspec-from-mercator') expected = _load_json('nuspec-expected') assert compare_dictionaries(normalize(data['items'][0]), expected)
def test_transforming_gradle(): """Test normalizing of pom.xml data.""" data = _load_json('gradle-from-mercator') expected = _load_json('gradle-expected') assert compare_dictionaries(normalize(data['items'][0]), expected)
def test_transforming_npm_shrinkwrap_data(): """Test normalizing of npm's shrinkwrap.json data.""" data = _load_json('npm-with-shrinkwrap-json-from-mercator') expected = _load_json('npm-with-shrinkwrap-json-expected') assert compare_dictionaries(normalize(data), expected)
def test_transforming_metadata_json(): """Test normalizing of data from metadata.json.""" data = _load_json('metadata-json-from-mercator') expected = _load_json('metadata-json-expected') assert normalize(data['items'][0]) == expected
def test_transforming_requirements_txt(): """Test normalizing of data from requirements.txt.""" data = _load_json('requirements-txt-from-mercator') expected = _load_json('requirements-txt-expected') assert normalize(data['items'][0]) == expected
def test_transforming_pkginfo(): """Test normalizing of data from PKG-INFO.""" data = _load_json('PKG-INFO-from-mercator') expected = _load_json('PKG-INFO-expected') assert normalize(data['items'][0]) == expected
def test_transforming_setup_py(): """Test normalizing of data from setup.py.""" data = _load_json('setup-py-from-mercator') expected = _load_json('setup-py-expected') assert normalize(data['items'][0]) == expected