def test_init(self): valid_configs = [ read_slicer_config(None), # Allow empty configuration object 'slicer.ini', # Allow file to be loaded None, # Allow no file 'abc/de/F', # Allow wrong path ] invalid_configs = [Workspace, 2] for config in valid_configs: Workspace(config=config) for config in invalid_configs: with self.assertRaises(ConfigurationError, msg='Expect to raise for config = "%s"' % config): Workspace(config=config)
def test_cube_with_dimensions_in_two_namespaces(self): ws = Workspace() ws.import_model(self.model_path("model.json"), namespace="store1") ws.import_model(self.model_path("other.json"), namespace="store2") # This should not pass, since the dimension is in another namespace with self.assertRaises(NoSuchDimensionError): ws.cube("store2.other") ws = Workspace() ws.import_model(self.model_path("model.json"), namespace="default") ws.import_model(self.model_path("other.json"), namespace="store2") # This should pass, since the dimension is in the default namespace ws.cube("store2.other")
def test_duplicate_dimension(self): ws = Workspace() ws.import_model(self.model_path("templated_dimension.json")) model = {"dimensions": [{"name": "date"}]} with self.assertRaises(ModelError): ws.import_model(model)
def test_external_template(self): ws = Workspace() ws.import_model(self.model_path("templated_dimension.json")) ws.import_model(self.model_path("templated_dimension_ext.json")) dim = ws.dimension("another_date") self.assertEqual("another_date", dim.name) self.assertEqual(3, len(dim.levels))
def create_local_workspace(config, cubes_root): """ Returns or creates a thread-local instance of Workspace """ if not hasattr(data, 'workspace'): data.workspace = Workspace(config=config, cubes_root=cubes_root) return data.workspace
def test_get_namespace_cube(self): ws = Workspace() ws.import_model(self.model_path("model.json"), namespace="local") with self.assertRaises(NoSuchCubeError): cube = ws.cube("contracts") cube = ws.cube("local.contracts") self.assertEqual("local.contracts", cube.name)
def test_template(self): ws = Workspace() ws.import_model(self.model_path("templated_dimension.json")) dim = ws.dimension("date") self.assertEqual("date", dim.name) self.assertEqual(3, len(dim.levels)) dim = ws.dimension("start_date") self.assertEqual("start_date", dim.name) self.assertEqual(3, len(dim.levels)) dim = ws.dimension("end_date") self.assertEqual("end_date", dim.name)
def test_local_dimension(self): # Test whether we can use local dimension with the same name as the # public one ws = Workspace() ws.import_model(self.model_path("model_public_dimensions.json")) ws.import_model(self.model_path("model_private_dimensions.json")) dim = ws.dimension("date") self.assertEqual(3, len(dim.levels)) self.assertEqual(["year", "month", "day"], dim.level_names) cube = ws.cube("events") dim = cube.dimension("date") self.assertEqual(["year", "month", "day"], dim.level_names) cube = ws.cube("lonely_yearly_events") dim = cube.dimension("date") self.assertEqual(["lonely_year"], dim.level_names)
def default_workspace(self, model_name=None): model_name = model_name or "model.json" config = read_slicer_config(self.data_path("slicer.ini")) ws = Workspace(config=config) ws.import_model(self.model_path("model.json")) return ws