@@ -0,0 +1,2013 @@
+# -*- encoding: utf-8 -*-%0Afrom __future__ import print_function%0Aimport unittest%0Aimport mock%0Afrom autosklearn.util.backend import Backend%0A%0A%0Aclass BackendModelsTest(unittest.TestCase):%0A%0A    class BackendStub(Backend):%0A%0A        def __init__(self, model_directory):%0A            self.__class__ = Backend%0A            self.get_model_dir = lambda: model_directory%0A%0A    def setUp(self):%0A        self.model_directory = '/model_directory/'%0A        self.backend = self.BackendStub(self.model_directory)%0A        self.BackendStub.get_model_dir = lambda x: 42%0A%0A    @mock.patch('six.moves.cPickle.load')%0A    @mock.patch('__builtin__.open')%0A    def test_loads_model_by_seed_and_id(self, openMock, pickleLoadMock):%0A        seed = 13%0A        idx = 17%0A        expected_model = self._setup_load_model_mocks(openMock, pickleLoadMock, seed, idx)%0A%0A        actual_model = self.backend.load_model_by_seed_and_id(seed, idx)%0A%0A        self.assertEqual(expected_model, actual_model)%0A%0A    @mock.patch('six.moves.cPickle.load')%0A    @mock.patch('__builtin__.open')%0A    def test_loads_models_by_identifiers(self, openMock, pickleLoadMock):%0A        seed = 13%0A        idx = 17%0A        expected_model = self._setup_load_model_mocks(openMock, pickleLoadMock, seed, idx)%0A        expected_dict = %7B (seed, idx): expected_model %7D%0A%0A        actual_dict = self.backend.load_models_by_identifiers(%5B(seed, idx)%5D)%0A%0A        self.assertIsInstance(actual_dict, dict)%0A        self.assertDictEqual(expected_dict, actual_dict)%0A%0A    def _setup_load_model_mocks(self, openMock, pickleLoadMock, seed, idx):%0A        model_path = '/model_directory/%25s.%25s.model' %25 (seed, idx)%0A        file_handler = 'file_handler'%0A        expected_model = 'model'%0A%0A        fileMock = mock.MagicMock()%0A        fileMock.__enter__.return_value = file_handler%0A%0A        openMock.side_effect = lambda path, flag: fileMock if path == model_path and flag == 'rb' else None%0A        pickleLoadMock.side_effect = lambda fh: expected_model if fh == file_handler else None%0A%0A        return expected_model

Test new backend methods