Exemplo n.º 1
0
class PylsyTableTests(unittest.TestCase):
    def setUp(self):
        attributes = ["name", "age"]
        self.table = PylsyTable(attributes)

    def tearDown(self):
        self.table = None

    def testCreateTable(self):
        name = ["a", "b"]
        self.table.add_data("name", name)
        age = [1, 2]
        self.table.add_data("age", age)
        correct_file = open('correct.out', 'r')
        correctPrint = correct_file.read()
        try:
            import io
            from contextlib import redirect_stdout
            with io.StringIO() as buf, redirect_stdout(buf):
                print('redirected')
                output = buf.getvalue()
                self.assertEqual(output, correctPrint)
        except ImportError:
            import sys
            f_handler = open('test.out', 'w')
            sys.stdout = f_handler
            self.table.create_table()
            f_handler.close()
            f_handler = open('test.out', 'r')
            self.assertEqual(f_handler.read(), correctPrint)
Exemplo n.º 2
0
class PylsyTableTests(unittest.TestCase):

    def setUp(self):
        attributes = ["name", "age"]
        self.table = PylsyTable(attributes)

    def tearDown(self):
        self.table = None

    def testCreateTable(self):
        name = ["a", "b"]
        self.table.add_data("name", name)
        age = [1, 2]
        self.table.add_data("age", age)
        correct_file = open('correct.out', 'r')
        correctPrint = correct_file.read()
        try:
            import io
            from contextlib import redirect_stdout
            with io.StringIO() as buf, redirect_stdout(buf):
                print('redirected')
                output = buf.getvalue()
                self.assertEqual(output, correctPrint)
        except ImportError:
            import sys
            f_handler = open('test.out', 'w')
            sys.stdout = f_handler
            self.table.create_table()
            f_handler.close()
            f_handler = open('test.out', 'r')
            self.assertEqual(f_handler.read(), correctPrint)
Exemplo n.º 3
0
 def setUp(self):
     attributes = ["name", "age"]
     self.table = PylsyTable(attributes)
Exemplo n.º 4
0
def main():
    attributes = ["name", "age", "sex", "id", "time"]
    table = PylsyTable(attributes)
    name = ["sun", "lsy", "luna", "leviathan"]
    table.add_data("name", name)
    age = [20, 21, 23, 25]
    table.add_data("age", age)
    sex = ["M", "F", "F", "F"]
    table.add_data("sex", sex)
    id = [2001, 2005, 4242, 02]
    table.add_data("id", id)
    time = [
        "2015-8-10 11:29:54", "2014-06-08 13:25:07", "2014-06-0813:25:07",
        "2014-06-08 13:25:07"
    ]
    table.add_data("time", time)
    table.create_table()
Exemplo n.º 5
0
def main():
    attributes=["name","age","sex","id","time"]
    table=PylsyTable(attributes)
    name=["sun","lsy","luna","leviathan"]
    table.add_data("name",name)
    age=[20,21,23,25]
    table.add_data("age",age)
    sex=["M","F","F","F"]
    table.add_data("sex",sex)
    id=[2001,2005,4242,02]
    table.add_data("id",id)
    time=["2015-8-10 11:29:54","2014-06-08 13:25:07","2014-06-0813:25:07","2014-06-08 13:25:07"]
    table.add_data("time",time)
    table.create_table()
Exemplo n.º 6
0
 def setUp(self):
     attributes = ["name", "age"]
     self.table = PylsyTable(attributes)