def test_has_details(self): """Level "has_details" flag""" attrs = attribute_list(["year"]) level = Level("year", attrs) self.assertFalse(level.has_details) attrs = attribute_list(["month", "month_name"]) level = Level("month", attrs) self.assertTrue(level.has_details)
def setUp(self): self.levels = [ Level("year", attributes=["year"]), Level("month", attributes=["month", "month_name", "month_sname"]), Level("day", attributes=["day"]), Level("week", attributes=["week"]) ] self.level_names = [level.name for level in self.levels] self.dimension = Dimension("date", levels=self.levels) levels = [self.levels[0], self.levels[1], self.levels[2]] self.hierarchy = Hierarchy("default", levels)
def test_comparison(self): """Comparison of level instances""" attrs = attribute_list(["info", "code", "name"]) level1 = Level("product", attrs, key="code", label_attribute="name") level2 = Level("product", attrs, key="code", label_attribute="name") level3 = Level("product", attrs) attrs = attribute_list(["month", "month_name"]) level4 = Level("product", attrs) self.assertEqual(level1, level2) self.assertNotEqual(level2, level3) self.assertNotEqual(level2, level4)
def test_simplify(self): """Simplification of attribute reference (with and without details)""" level = Level("name", attributes=["name"]) dim = Dimension("group", levels=[level]) attr = dim.attribute("name") self.assertEqual("name", attr.name) self.assertEqual("name", str(attr)) self.assertEqual("group", attr.ref()) self.assertEqual("group.name", attr.ref(simplify=False)) self.assertEqual("group", attr.ref(simplify=True)) level = Level("name", attributes=["key", "name"]) dim = Dimension("group", levels=[level]) attr = dim.attribute("name") self.assertEqual("name", attr.name) self.assertEqual("name", str(attr)) self.assertEqual("group.name", attr.ref()) self.assertEqual("group.name", attr.ref(simplify=False)) self.assertEqual("group.name", attr.ref(simplify=True))
def test_key_label_attributes(self): """Test key and label attributes - explicit and implicit""" attrs = attribute_list(["code"]) level = Level("product", attrs) self.assertIsInstance(level.key, Attribute) self.assertEqual("code", str(level.key)) self.assertIsInstance(level.label_attribute, Attribute) self.assertEqual("code", str(level.label_attribute)) attrs = attribute_list(["code", "name"]) level = Level("product", attrs) self.assertIsInstance(level.key, Attribute) self.assertEqual("code", str(level.key)) self.assertIsInstance(level.label_attribute, Attribute) self.assertEqual("name", str(level.label_attribute)) attrs = attribute_list(["info", "code", "name"]) level = Level("product", attrs, key="code", label_attribute="name") self.assertIsInstance(level.key, Attribute) self.assertEqual("code", str(level.key)) self.assertIsInstance(level.label_attribute, Attribute) self.assertEqual("name", str(level.label_attribute)) # Test key/label in full desc desc = { "name": "product", "attributes": ["info", "code", "name"], "label_attribute": "name", "key": "code" } level = create_level(desc) self.assertIsInstance(level.key, Attribute) self.assertEqual("code", str(level.key)) self.assertIsInstance(level.label_attribute, Attribute) self.assertEqual("name", str(level.label_attribute))
def test_create_attribute(self): """Coalesce attribute object (string or Attribute instance)""" level = Level("name", attributes=["key", "name"]) dim = Dimension("group", levels=[level]) obj = create_attribute("name") self.assertIsInstance(obj, Attribute) self.assertEqual("name", obj.name) obj = create_attribute({"name": "key"}) obj.dimension = dim self.assertIsInstance(obj, Attribute) self.assertEqual("key", obj.name) self.assertEqual(dim, obj.dimension) attr = dim.attribute("key") obj = create_attribute(attr) obj.dimension = dim self.assertIsInstance(obj, Attribute) self.assertEqual("key", obj.name) self.assertEqual(obj, attr)
def test_operators(self): """Level to string conversion""" self.assertEqual("date", str(Level("date", ["foo"])))