def test_convert(self): self.data["time"] = datetime.datetime(2013, 1, 1) fd = FormatedDict(self.data) dd = fd.to_dict(convert={datetime.datetime: lambda x: x.strftime("%Y-%m-%d")}) self.assertIn("time", dd) self.assertEqual(dd["time"], "2013-01-01") fd = FormatedDict(self.data) dd = fd.to_dict(convert={"time": lambda x: x.strftime("%Y-%m-%d")}) self.assertIn("time", dd) self.assertEqual(dd["time"], "2013-01-01") # nested convert self.data["time"] = {"time": datetime.datetime(2013, 1, 1)} fd = FormatedDict(self.data) dd = fd.to_dict(convert={"time|time": lambda x: x.strftime("%Y-%m-%d")}) self.assertIn("time", dd) self.assertIn("time", dd["time"]) self.assertEqual(dd["time"]["time"], "2013-01-01")
def test_convert(self): self.data['time'] = datetime.datetime(2013, 1, 1) fd = FormatedDict(self.data) dd = fd.to_dict( convert={datetime.datetime: lambda x: x.strftime("%Y-%m-%d")}) self.assertIn('time', dd) self.assertEqual(dd['time'], '2013-01-01') fd = FormatedDict(self.data) dd = fd.to_dict(convert={'time': lambda x: x.strftime("%Y-%m-%d")}) self.assertIn('time', dd) self.assertEqual(dd['time'], '2013-01-01') # nested convert self.data['time'] = {'time': datetime.datetime(2013, 1, 1)} fd = FormatedDict(self.data) dd = fd.to_dict( convert={'time|time': lambda x: x.strftime("%Y-%m-%d")}) self.assertIn('time', dd) self.assertIn('time', dd['time']) self.assertEqual(dd['time']['time'], '2013-01-01')
def test_to_dict(self): self.assertIn("a", self.data) self.assertIn("b", self.data) fd = FormatedDict(self.data, format="a") new = fd.to_dict() self.assertIn("a", new) self.assertNotIn("b", new) self.assertIn("a", self.data) self.assertIn("b", self.data) self.assertNotIn("aa", self.data) fd = FormatedDict(self.data, format="a=>aa") new = fd.to_dict() self.assertIn("aa", new) self.assertNotIn("aa", self.data) self.assertIn("a", self.data) fd = FormatedDict(self.data, format="-a") new = fd.to_dict() self.assertNotIn("a", new) self.assertIn("b", new) self.assertIn("z", new) self.assertIn("a", self.data)
def test_to_dict(self): self.assertIn('a', self.data) self.assertIn('b', self.data) fd = FormatedDict(self.data, format="a") new = fd.to_dict() self.assertIn('a', new) self.assertNotIn('b', new) self.assertIn('a', self.data) self.assertIn('b', self.data) self.assertNotIn('aa', self.data) fd = FormatedDict(self.data, format="a=>aa") new = fd.to_dict() self.assertIn('aa', new) self.assertNotIn('aa', self.data) self.assertIn('a', self.data) fd = FormatedDict(self.data, format="-a") new = fd.to_dict() self.assertNotIn('a', new) self.assertIn('b', new) self.assertIn('z', new) self.assertIn('a', self.data)