def test_pkg_manager_view_extras_requires(self): working_set = self.setup_requirements_json() working_set.add( pkg_resources.Distribution( metadata=MockProvider({ 'requires.txt': '[dev]\ncalmpy.pip', }), project_name='site', version='0.0.0', )) driver = cli.PackageManagerDriver( pkg_manager_bin='mgr', pkgdef_filename='requirements.json', dep_keys=('require', ), ) result = driver.pkg_manager_view('site') self.assertEqual(result, { "require": {}, "name": "site", }) result = driver.pkg_manager_view('site[dev]') self.assertEqual(result, { "require": { "setuptools": "25.1.6" }, "name": "site[dev]", })
def test_read_dist_line_list(self): # We will mock up a Distribution object with some fake metadata. mock_provider = MockProvider({ 'list.txt': 'reg1\nreg2', }) mock_dist = pkg_resources.Distribution(metadata=mock_provider, project_name='dummydist', version='0.0.0') results = calmjs_dist.read_dist_line_list(mock_dist, 'list.txt') self.assertEqual(results, ['reg1', 'reg2'])
def test_read_dist_line_io_error(self): # We will mock up a Distribution object with some fake metadata. stub_stdouts(self) mock_provider = MockProvider({ 'list.txt': None # the MockProvider emulates IOError }) mock_dist = pkg_resources.Distribution(metadata=mock_provider, project_name='dummydist', version='0.0.0') results = calmjs_dist.read_dist_line_list(mock_dist, 'list.txt') self.assertEqual(results, [])
def test_get_dist_package_read_error(self): # Quiet stdout from distutils logs stub_stdouts(self) mock_provider = MockProvider({ self.pkgname: None, # None will emulate IO error. }) mock_dist = pkg_resources.Distribution(metadata=mock_provider, project_name='dummydist', version='0.0.0') results = calmjs_dist.read_dist_egginfo_json(mock_dist) # Should still not fail. self.assertIsNone(results)
def test_read_dist_egginfo_json(self): package_json = {"dependencies": {"left-pad": "~1.1.1"}} # We will mock up a Distribution object with some fake metadata. mock_provider = MockProvider({ self.pkgname: json.dumps(package_json), }) mock_dist = pkg_resources.Distribution(metadata=mock_provider, project_name='dummydist', version='0.0.0') results = calmjs_dist.read_dist_egginfo_json(mock_dist) self.assertEqual(results, package_json)
def setup_requirements_json(self): # what kind of bizzaro world do the following users live in? requirements = {"require": {"setuptools": "25.1.6"}} mock_provider = MockProvider({ 'requirements.json': json.dumps(requirements), }) # seriously lolwat? mock_dist = pkg_resources.Distribution(metadata=mock_provider, project_name='calmpy.pip', version='0.0.0') working_set = pkg_resources.WorkingSet() working_set.add(mock_dist) stub_item_attr_value(self, dist, 'default_working_set', working_set) return working_set
def test_get_dist_package_decoding_error(self): # Quiet stdout from distutils logs stub_stdouts(self) # trailing comma package_json = '{"dependencies": {"left-pad": "~1.1.1"},}' # bad data could be created by a competiting package. mock_provider = MockProvider({ self.pkgname: package_json, }) mock_dist = pkg_resources.Distribution(metadata=mock_provider, project_name='dummydist', version='0.0.0') results = calmjs_dist.read_dist_egginfo_json(mock_dist) # Should still not fail. self.assertIsNone(results)
def test_read_dist_egginfo_json_alternative_name_args(self): package_json = {"dependencies": {"left-pad": "~1.1.1"}} # We will mock up a Distribution object with some fake metadata. mock_provider = MockProvider({ 'bower.json': json.dumps(package_json), }) mock_dist = pkg_resources.Distribution(metadata=mock_provider, project_name='dummydist', version='0.0.0') results = calmjs_dist.read_dist_egginfo_json(mock_dist, filename='bower.json') self.assertEqual(results, package_json) working_set = pkg_resources.WorkingSet() working_set.add(mock_dist) self.assertEqual( package_json, calmjs_dist.read_egginfo_json('dummydist', filename='bower.json', working_set=working_set)) # Finally do the flattening flattened_json = { "dependencies": { "left-pad": "~1.1.1" }, "devDependencies": {} } self.assertEqual( flattened_json, calmjs_dist.flatten_dist_egginfo_json([mock_dist], filename='bower.json', working_set=working_set)) self.assertEqual( flattened_json, calmjs_dist.flatten_egginfo_json(['dummydist'], filename='bower.json', working_set=working_set))