def test_cut_depth(self): dim = self.cube.dimension("date") self.assertEqual(1, PointCut(dim, [1]).level_depth()) self.assertEqual(3, PointCut(dim, [1, 1, 1]).level_depth()) self.assertEqual(1, RangeCut(dim, [1], [1]).level_depth()) self.assertEqual(3, RangeCut(dim, [1, 1, 1], [1]).level_depth()) self.assertEqual(1, SetCut(dim, [[1], [1]]).level_depth()) self.assertEqual(3, SetCut(dim, [[1], [1], [1, 1, 1]]).level_depth())
def test_multi_slice(self): full_cube = Cell(self.cube) cuts_list = (PointCut("date", [2010]), PointCut("cpv", [50, 20]), PointCut("supplier", [1234])) cell_list = full_cube.multi_slice(cuts_list) self.assertEqual(3, len(cell_list.cuts)) self.assertRaises(CubesError, full_cube.multi_slice, {})
def test_get_cell_dimension_cut(self): full_cube = Cell(self.cube) cell = full_cube.slice(PointCut("date", [2010])) cell = cell.slice(PointCut("supplier", [1234])) cut = cell.cut_for_dimension("date") self.assertEqual(str(cut.dimension), "date") self.assertRaises(NoSuchDimensionError, cell.cut_for_dimension, "someunknown") cut = cell.cut_for_dimension("cpv") self.assertEqual(cut, None)
def test_set_cut_string(self): cut = SetCut("foo", [["1"], ["2", "3"], ["qwe", "asd", "100"]]) self.assertEqual("foo:1;2,3;qwe,asd,100", str(cut)) self.assertEqual(cut, cut_from_string("foo:1;2,3;qwe,asd,100")) # single-element SetCuts cannot go round trip, they become point cuts cut = SetCut("foo", [["a+b"]]) self.assertEqual("foo:a+b", str(cut)) self.assertEqual(PointCut("foo", ["a+b"]), cut_from_string("foo:a+b")) cut = SetCut("foo", [["a-b"]]) self.assertEqual("foo:a\-b", str(cut)) self.assertEqual(PointCut("foo", ["a-b"]), cut_from_string("foo:a\-b"))
def test_cutting(self): full_cube = Cell(self.cube) self.assertEqual(self.cube, full_cube.cube) self.assertEqual(0, len(full_cube.cuts)) cell = full_cube.slice(PointCut("date", [2010])) self.assertEqual(1, len(cell.cuts)) cell = cell.slice(PointCut("supplier", [1234])) cell = cell.slice(PointCut("cpv", [50, 20])) self.assertEqual(3, len(cell.cuts)) self.assertEqual(self.cube, cell.cube) # Adding existing slice should result in changing the slice properties cell = cell.slice(PointCut("date", [2011])) self.assertEqual(3, len(cell.cuts))
def test_cut_string_conversions(self): cut = PointCut("foo", ["10"]) self.assertEqual("foo:10", str(cut)) self.assertEqual(cut, cut_from_string("foo:10")) cut = PointCut("foo", ["123_abc_", "10", "_"]) self.assertEqual("foo:123_abc_,10,_", str(cut)) self.assertEqual(cut, cut_from_string("foo:123_abc_,10,_")) cut = PointCut("foo", ["123_ abc_"]) self.assertEqual(r"foo:123_ abc_", str(cut)) self.assertEqual(cut, cut_from_string("foo:123_ abc_")) cut = PointCut("foo", ["a-b"]) self.assertEqual("foo:a\-b", str(cut)) self.assertEqual(cut, cut_from_string("foo:a\-b")) cut = PointCut("foo", ["a+b"]) self.assertEqual("foo:a+b", str(cut)) self.assertEqual(cut, cut_from_string("foo:a+b"))
def test_slice_drilldown(self): cut = PointCut("date", []) original_cell = Cell(self.cube, [cut]) cell = original_cell.drilldown("date", 2010) self.assertEqual([2010], cell.cut_for_dimension("date").path) cell = cell.drilldown("date", 1) self.assertEqual([2010, 1], cell.cut_for_dimension("date").path) cell = cell.drilldown("date", 2) self.assertEqual([2010, 1, 2], cell.cut_for_dimension("date").path)
def test_cut_from_dict(self): # d = {"type":"point", "path":[2010]} # self.assertRaises(Exception, cubes.cut_from_dict, d) d = {"type": "point", "path": [2010], "dimension": "date", "level_depth": 1, "hierarchy": None, "invert": False, "hidden": False} cut = cut_from_dict(d) tcut = PointCut("date", [2010]) self.assertEqual(tcut, cut) self.assertEqual(dict(d), tcut.to_dict()) self._assert_invert(d, cut, tcut) d = {"type": "range", "from": [2010], "to": [2012, 10], "dimension": "date", "level_depth": 2, "hierarchy": None, "invert": False, "hidden": False} cut = cut_from_dict(d) tcut = RangeCut("date", [2010], [2012, 10]) self.assertEqual(tcut, cut) self.assertEqual(dict(d), tcut.to_dict()) self._assert_invert(d, cut, tcut) d = {"type": "set", "paths": [[2010], [2012, 10]], "dimension": "date", "level_depth": 2, "hierarchy": None, "invert": False, "hidden": False} cut = cut_from_dict(d) tcut = SetCut("date", [[2010], [2012, 10]]) self.assertEqual(tcut, cut) self.assertEqual(dict(d), tcut.to_dict()) self._assert_invert(d, cut, tcut) self.assertRaises(ArgumentError, cut_from_dict, {"type": "xxx"})
def test_cut_from_dict(self): # d = {"type":"point", "path":[2010]} # self.assertRaises(Exception, cubes.cut_from_dict, d) d = { "type": "point", "path": [2010], "dimension": "date", "level_depth": 1, "hierarchy": None, "invert": False, "hidden": False } cut = cut_from_dict(d) tcut = PointCut("date", [2010]) self.assertEqual(tcut, cut) self.assertEqual(dict(d), tcut.to_dict()) self._assert_invert(d, cut, tcut) d = { "type": "range", "from": [2010], "to": [2012, 10], "dimension": "date", "level_depth": 2, "hierarchy": None, "invert": False, "hidden": False } cut = cut_from_dict(d) tcut = RangeCut("date", [2010], [2012, 10]) self.assertEqual(tcut, cut) self.assertEqual(dict(d), tcut.to_dict()) self._assert_invert(d, cut, tcut) d = { "type": "set", "paths": [[2010], [2012, 10]], "dimension": "date", "level_depth": 2, "hierarchy": None, "invert": False, "hidden": False } cut = cut_from_dict(d) tcut = SetCut("date", [[2010], [2012, 10]]) self.assertEqual(tcut, cut) self.assertEqual(dict(d), tcut.to_dict()) self._assert_invert(d, cut, tcut) self.assertRaises(ArgumentError, cut_from_dict, {"type": "xxx"})
def test_hierarchy_cut(self): cut = PointCut("date", ["10"], "dqmy") self.assertEqual("date@dqmy:10", str(cut)) self.assertEqual(cut, cut_from_string("date@dqmy:10"))