예제 #1
0
 def test_config_width_fail(self):
     with io.StringIO() as buf, redirect_stdout(buf):
         obj = ObjTest({"lst": ["This", "is", "for", "testing"]})
         objprint(obj, width=5)
         output = buf.getvalue()
     expected = "<ObjTest\n  .lst = [\n    'This',\n    'is',\n    'for',\n    'testing'\n  ]\n>\n"
     self.assertEqual(output, expected)
예제 #2
0
 def test_print_to_file(self):
     fname = "./test.txt"
     with open(fname, "w") as f:
         objprint(A(), file=f)
     with open(fname, "r") as f:
         self.assertGreater(len(f.read()), 0)
     os.remove(fname)
예제 #3
0
 def test_config_exclude(self):
     with io.StringIO() as buf, redirect_stdout(buf):
         obj = ObjTest({"elem1": 1, "elem2": 2, "elem3": 3})
         objprint(obj, indent=1, exclude=['elem3'])
         output = buf.getvalue()
     expected = "<ObjTest\n .elem1 = 1,\n .elem2 = 2\n>\n"
     self.assertEqual(expected, output)
예제 #4
0
 def test_config_width(self):
     with io.StringIO() as buf, redirect_stdout(buf):
         obj = ObjTest({"lst": ['a', 'b']})
         objprint(obj, width=10)
         output = buf.getvalue()
     lst = "<ObjTest\n  .lst = ['a', 'b']\n>\n"
     self.assertEqual(output, lst)
예제 #5
0
 def test_element(self):
     with io.StringIO() as buf, redirect_stdout(buf):
         obj = ObjTest({"first": "east", "second": "west", "third": "north"})
         objprint(obj, elements=2)
         output = buf.getvalue()
     self.assertIn("first", output)
     self.assertIn("second", output)
     self.assertNotIn("third", output)
예제 #6
0
    def test_config_indent(self):
        with io.StringIO() as buf, redirect_stdout(buf):
            obj = ObjTest({"name": "Alpha"})
            objprint(obj, indent=3)
            output = buf.getvalue()

        expectedString = "<ObjTest\n   .name = 'Alpha'\n>\n"
        self.assertEqual(expectedString, output)
예제 #7
0
    def test_wrapper(self):
        with io.StringIO() as buf, redirect_stdout(buf):
            print(TestWrapper())
            output = buf.getvalue()

        with io.StringIO() as buf, redirect_stdout(buf):
            objprint(TestWrapper(), include=['color1', 'color2'])
            expected = buf.getvalue()

        self.assertEqual(output, expected)
예제 #8
0
    def test_single_class(self):
        with io.StringIO() as buf, redirect_stdout(buf):
            print(DecoratedClass())
            output = buf.getvalue()

        with io.StringIO() as buf, redirect_stdout(buf):
            objprint(DecoratedClass())
            expected = buf.getvalue()

        self.assertEqual(expected, output)
예제 #9
0
 def test_config_element(self):
     config(elements=2)
     e = ObjTest({"first": 1, "second": 2, "third": 3})
     with io.StringIO() as buf, redirect_stdout(buf):
         objprint(e)
         output = buf.getvalue()
     self.assertIn("first", output)
     self.assertIn("second", output)
     self.assertNotIn("third", output)
     config(elements=None)
예제 #10
0
    def test_depth(self):
        with io.StringIO() as buf, redirect_stdout(buf):

            e = ObjTest({"element": "east", "second": "west"})
            depth2 = ObjTest({"attri": e, "inDepth2": "depth2"})
            depth1 = ObjTest({"content": depth2, "inDepth1": "depth1"})
            multiDepth = ObjTest({"name": "depthTest", "first": depth1})

            objprint(multiDepth, depth=2)
            output = buf.getvalue()
        self.assertIn("depthTest", output)
        self.assertIn("depth1", output)
        self.assertNotIn("depth2", output)
        self.assertNotIn("element", output)
예제 #11
0
    def test_two_class(self):
        actual = []
        with io.StringIO() as buf, redirect_stdout(buf):
            print(DecoratedClass())
            output = buf.getvalue()
            split_line_dec = output.splitlines()
            actual = split_line_dec[1:]

        expected = []
        with io.StringIO() as buf, redirect_stdout(buf):
            objprint(NotDecorated())
            expect = buf.getvalue()
            split_line_nodec = expect.splitlines()
            expected = split_line_nodec[1:]

        self.assertEqual(expected, actual)
예제 #12
0
 def test_print_to_buffer(self):
     with io.StringIO() as buf:
         objprint(A(), file=buf)
         self.assertGreater(len(buf.getvalue()), 0)
예제 #13
0
 def test_print(self):
     with io.StringIO() as buf, redirect_stdout(buf):
         objprint(A())
         self.assertTrue(len(buf.getvalue()) > 0)
예제 #14
0
 def test_objprint(self):
     with io.StringIO() as buf, redirect_stdout(buf):
         b = ObjTest({})
         objprint(b, indent=5, depth=2, width=60)
         self.assertTrue(len(buf.getvalue()) > 0)