class XmlSimpleSerializerTest(unittest.TestCase):
    def setUp(self):
        self.serializer = XmlSimpleDictionarySerializer()
        self.to_be_removed_file = None

    def tearDown(self):
        if self.to_be_removed_file != None:
            os.remove(self.to_be_removed_file)

    def test_empty_dictionary(self):
        empty_dict = dict()
        f, fname = tempfile.mkstemp()
        self.to_be_removed_file = fname
        f = open(f, "wb")
        serialized_str = self.serializer.serialize(empty_dict, "my_dict", "serialized").encode("utf-8")
        self.assertTrue(len(serialized_str) > 0)
        f.write(serialized_str)
        f.close()
        result = self.serializer.deserialize(open(fname, "rb"), "my_dict", "serialized")
        self.assertEqual(len(result.keys()), 0)

    def test_trivial_dictionary(self):
        empty_dict = {"int_value": 1}
        f, fname = tempfile.mkstemp()
        self.to_be_removed_file = fname
        f = open(f, "wb")
        serialized_str = self.serializer.serialize(empty_dict, "my_dict", "serialized").encode("utf-8")
        f.write(serialized_str)
        f.close()
        result = self.serializer.deserialize(open(fname, "rb"), "my_dict", "serialized")
        self.assertEqual(len(result.keys()), 1)
        self.assertEqual(empty_dict["int_value"], 1)
 def setUp(self):
     self.serializer = XmlSimpleDictionarySerializer()
     self.to_be_removed_file = None