def test_set_hierarchy(self): test_hierarchy = [["0", "*"], ["1", "*"]] dataset = Dataset(self.test_data) dataset._set_attribute_type("id", AttributeType.QUASIIDENTIFYING) dataset.set_hierarchy("id", test_hierarchy) self.assertEqual(dataset._attributes[0].hierarchy, test_hierarchy)
def test_set_hierarchy__not_valid_attribute_name(self): test_hierarchy = [["0", "*"], ["1", "*"]] dataset = Dataset(self.test_data) dataset._set_attribute_type("id", AttributeType.QUASIIDENTIFYING) with self.assertRaises(KeyError): dataset.set_hierarchy("fail", test_hierarchy) self.assertIsNone(dataset._attributes[0].hierarchy)
def test_set_hierarchy_with_pandas(self): test_hierarchy = [["0", "*"], ["1", "*"]] hierarchy_df = pandas.DataFrame(test_hierarchy) dataset = Dataset(self.test_data) dataset._set_attribute_type("id", AttributeType.QUASIIDENTIFYING) dataset.set_hierarchy("id", hierarchy_df) self.assertEqual(dataset._attributes[0].hierarchy, test_hierarchy)
def test_set_hierarchy__not_valid_attribute_type(self): test_hierarchy = [["0", "*"], ["1", "*"]] dataset = Dataset(self.test_data) dataset._set_attribute_type("id", AttributeType.INSENSITIVE) with self.assertRaises(ValueError): dataset.set_hierarchy("id", test_hierarchy) self.assertIsNone(dataset._attributes[0].hierarchy) self.assertIsNot(test_hierarchy, dataset._attributes[0].hierarchy)