Esempio n. 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')
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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:'))
Esempio n. 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:'))
Esempio n. 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)
Esempio n. 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')
Esempio n. 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)
Esempio n. 10
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)
Esempio n. 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)
Esempio n. 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'
        )
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)