def test_is_json_compat_bad_type(self): with self.assertRaises(ValueError) as e: calmjs_dist.is_json_compat(NotImplemented) self.assertEqual( str(e.exception), 'must be a JSON serializable object: ' 'NotImplemented is not JSON serializable')
def test_is_json_compat_bad_type(self): with self.assertRaises(ValueError) as e: calmjs_dist.is_json_compat(NotImplemented) msg = str(e.exception) self.assertIn('must be a JSON serializable object', msg) self.assertIn('NotImplemented', msg)
def test_is_json_compat_bad_type_in_dict(self): with self.assertRaises(ValueError) as e: calmjs_dist.is_json_compat( {'devDependencies': { 'left-pad': NotImplemented, }}) msg = str(e.exception) self.assertIn('must be a JSON serializable object', msg) self.assertIn('NotImplemented', msg)
def test_is_json_compat_bad_encode(self): with self.assertRaises(ValueError) as e: calmjs_dist.is_json_compat( '{' ' "devDependencies": {' ' "left-pad": "~1.1.1",' # trailing comma ' },' '}') self.assertTrue(str(e.exception).startswith('JSON decoding error:'))
def test_is_json_compat_bad_encode(self): with self.assertRaises(ValueError) as e: calmjs_dist.is_json_compat( '{' ' "devDependencies": {' ' "left-pad": "~1.1.1",' # trailing comma ' },' '}' ) self.assertTrue(str(e.exception).startswith('JSON decoding error:'))
def test_is_json_compat_bad_type_in_dict(self): with self.assertRaises(ValueError) as e: calmjs_dist.is_json_compat({ 'devDependencies': { 'left-pad': NotImplemented, } }) msg = str(e.exception) self.assertIn('must be a JSON serializable object', msg) self.assertIn('NotImplemented', msg)
def test_is_json_compat_bad_type_not_dict(self): with self.assertRaises(ValueError) as e: calmjs_dist.is_json_compat(1) self.assertEqual( str(e.exception), 'must be specified as a JSON serializable dict ' 'or a JSON deserializable string') with self.assertRaises(ValueError) as e: calmjs_dist.is_json_compat('"hello world"') self.assertEqual( str(e.exception), 'must be specified as a JSON serializable dict ' 'or a JSON deserializable string')
def test_is_json_compat_good_str(self): result = calmjs_dist.is_json_compat('{' ' "devDependencies": {' ' "left-pad": "~1.1.1"' ' }' '}') self.assertTrue(result)
def get_artifact_metadata(self, package_name): """ Return metadata of the artifacts built through this registry. """ filename = self.metadata.get(package_name) if not filename or not exists(filename): return {} with open(filename, encoding='utf8') as fd: contents = fd.read() try: is_json_compat(contents) except ValueError: logger.info("artifact metadata file '%s' is invalid", filename) return {} return json.loads(contents)
def test_is_json_compat_good_str(self): result = calmjs_dist.is_json_compat( '{' ' "devDependencies": {' ' "left-pad": "~1.1.1"' ' }' '}' ) self.assertTrue(result)
def test_is_json_compat_bad_type_not_dict(self): with self.assertRaises(ValueError) as e: calmjs_dist.is_json_compat(1) self.assertEqual( str(e.exception), 'must be specified as a JSON serializable dict ' 'or a JSON deserializable string' ) with self.assertRaises(ValueError) as e: calmjs_dist.is_json_compat('"hello world"') self.assertEqual( str(e.exception), 'must be specified as a JSON serializable dict ' 'or a JSON deserializable string' )
def test_is_json_compat_good_dict_with_none(self): # Possible to specify a null requirement to remove things. result = calmjs_dist.is_json_compat( { "devDependencies": { "left-pad": None }, }, ) self.assertTrue(result)
def test_is_json_compat_good_dict(self): result = calmjs_dist.is_json_compat( # trailing commas are fine in python dicts. { "devDependencies": { "left-pad": "~1.1.1", }, }, ) self.assertTrue(result)