def set_backend(self, *args): backend = args[0] self._is_installed(backend) jsonstruct.load_backend(*args) jsonstruct.set_preferred_backend(backend)
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_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_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'))
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'))
def test_load_backend(self): """Test that we can call jsonstruct.load_backend() """ jsonstruct.load_backend('simplejson', 'dumps', 'loads', ValueError)