예제 #1
0
 def test_makeDict_behavior(self):
     """
     Test if makeDict is returning the expected value.
     """
     headers = [["A", "B"], ["C", "D"]]
     values = [[1, 2], [3, 4]]
     target = {"A": {"C": 1, "D": 2}, "B": {"C": 3, "D": 4}}
     dict_with_default = makeDict(headers, values, default=0)
     dict_without_default = makeDict(headers, values)
     print("\t Testing makeDict general behavior")
     self.assertEqual(dict_with_default, target)
     self.assertEqual(dict_without_default, target)
예제 #2
0
 def test_makeDict_default_value(self):
     """
     Test if makeDict is returning a default value when specified.
     """
     headers = [["A", "B"], ["C", "D"]]
     values = [[1, 2], [3, 4]]
     dict_with_default = makeDict(headers, values, default=0)
     dict_without_default = makeDict(headers, values)
     print("\t Testing makeDict default value behavior")
     # Check if a default value is passed
     self.assertEqual(dict_with_default["X"]["Y"], 0)
     # Check if a KeyError is raised
     _func = lambda: dict_without_default["X"]["Y"]
     self.assertRaises(KeyError, _func)