示例#1
0
    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')
示例#2
0
    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)
示例#3
0
    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)
示例#4
0
    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)
示例#5
0
    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:'))
示例#6
0
    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:'))
示例#7
0
    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)
示例#8
0
    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')
示例#9
0
 def test_is_json_compat_good_str(self):
     result = calmjs_dist.is_json_compat('{'
                                         '    "devDependencies": {'
                                         '        "left-pad": "~1.1.1"'
                                         '    }'
                                         '}')
     self.assertTrue(result)
示例#10
0
文件: artifact.py 项目: calmjs/calmjs
    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)
示例#11
0
 def test_is_json_compat_good_str(self):
     result = calmjs_dist.is_json_compat(
         '{'
         '    "devDependencies": {'
         '        "left-pad": "~1.1.1"'
         '    }'
         '}'
     )
     self.assertTrue(result)
示例#12
0
    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'
        )
示例#13
0
    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)
示例#14
0
 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)
示例#15
0
 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)
示例#16
0
 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)
示例#17
0
 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)