from unittest import TestCase

from suger.data_operator.CsvUtils import CsvUtils


class TestCsvUtils(TestCase):
    def test_serialize(self):
        person1 = Person("Alice", 25)
        person2 = Person("Bob", 30)
        persons = [person1, person2]

        # Serialize list of objects
        csv_str = CsvUtils.serialize(persons)
        print(csv_str)

        # Deserialize list of objects
        persons_deserialized = CsvUtils.deserialize(csv_str, Person)
        for person in persons_deserialized:
            print(person.name, person.age)

        # Serialize single object
        csv_str = CsvUtils.serialize(person1)
        print(csv_str)

        # Deserialize single object
        person_deserialized = CsvUtils.deserialize(csv_str, Person)
        print(person_deserialized.name, person_deserialized.age)


class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age
