Esempio n. 1
0
    def set_backend(self, *args):
        backend = args[0]

        self._is_installed(backend)

        jsonstruct.load_backend(*args)
        jsonstruct.set_preferred_backend(backend)
Esempio n. 2
0
    def set_backend(self, *args):
        backend = args[0]

        self._is_installed(backend)

        jsonstruct.load_backend(*args)
        jsonstruct.set_preferred_backend(backend)
Esempio n. 3
0
    def test_load_backend_submodule(self):
        """Test that we can load a submodule as a backend

        """
        jsonstruct.load_backend('os.path', 'split', 'join', AttributeError)
        self.assertTrue('os.path' in jsonstruct.json._backend_names and
                        'os.path' in jsonstruct.json._encoders and
                        'os.path' in jsonstruct.json._decoders and
                        'os.path' in jsonstruct.json._encoder_options and
                        'os.path' in jsonstruct.json._decoder_exceptions)
    def test_load_backend_submodule(self):
        """Test that we can load a submodule as a backend

        """
        jsonstruct.load_backend('os.path', 'split', 'join', AttributeError)
        self.assertTrue('os.path' in jsonstruct.json._backend_names
                        and 'os.path' in jsonstruct.json._encoders
                        and 'os.path' in jsonstruct.json._decoders
                        and 'os.path' in jsonstruct.json._encoder_options
                        and 'os.path' in jsonstruct.json._decoder_exceptions)
Esempio n. 5
0
    def test_set_preferred_backend_allows_magic(self):
        """Tests that we can use the pluggable backends magically
        """
        backend = 'os.path'
        jsonstruct.load_backend(backend, 'split', 'join', AttributeError)
        jsonstruct.set_preferred_backend(backend)

        slash_hello, world = jsonstruct.encode('/hello/world')
        jsonstruct.remove_backend(backend)

        self.assertEqual(slash_hello, '/hello')
        self.assertEqual(world, 'world')
    def test_set_preferred_backend_allows_magic(self):
        """Tests that we can use the pluggable backends magically
        """
        backend = 'os.path'
        jsonstruct.load_backend(backend, 'split', 'join', AttributeError)
        jsonstruct.set_preferred_backend(backend)

        slash_hello, world = jsonstruct.encode('/hello/world')
        jsonstruct.remove_backend(backend)

        self.assertEqual(slash_hello, '/hello')
        self.assertEqual(world, 'world')
Esempio n. 7
0
    def test_load_backend_skips_bad_decoder_exceptions(self):
        """Test that we ignore bad decoder exceptions"""

        jsonstruct.load_backend('os.path', 'join', 'split', 'bad!')
        self.failIf(self._backend_is_partially_loaded('os.path'))
Esempio n. 8
0
    def test_load_backend_skips_bad_decode(self):
        """Test that we ignore bad decoders"""

        jsonstruct.load_backend('os.path', 'join', 'bad!', AttributeError)
        self.failIf(self._backend_is_partially_loaded('os.path'))
Esempio n. 9
0
    def test_load_backend(self):
        """Test that we can call jsonstruct.load_backend()

        """
        jsonstruct.load_backend('simplejson', 'dumps', 'loads', ValueError)
Esempio n. 10
0
    def test_load_backend_skips_bad_decoder_exceptions(self):
        """Test that we ignore bad decoder exceptions"""

        jsonstruct.load_backend('os.path', 'join', 'split', 'bad!')
        self.failIf(self._backend_is_partially_loaded('os.path'))
Esempio n. 11
0
    def test_load_backend_skips_bad_decode(self):
        """Test that we ignore bad decoders"""

        jsonstruct.load_backend('os.path', 'join', 'bad!', AttributeError)
        self.failIf(self._backend_is_partially_loaded('os.path'))
Esempio n. 12
0
    def test_load_backend(self):
        """Test that we can call jsonstruct.load_backend()

        """
        jsonstruct.load_backend('simplejson', 'dumps', 'loads', ValueError)