예제 #1
0
 def do_pprint(self, val):
     if val is None:
         self.info("Usage: pp <arg>")
     try:
         self.message(objprint.objstr(self._get_val(val)))
     except Exception as e:
         self.info("".join(traceback.format_exception_only(type(e), e)), end="")
예제 #2
0
 def test_dict(self):
     lsts = (
         ({}, "{}"),
         ({"Age": "19"}, "{'Age': '19'}"),
         ({"Number": 1, "Letter": 'a'}, "{'Letter': 'a', 'Number': 1}")
     )
     for obj, s in lsts:
         self.assertEqual(objstr(obj), s)
예제 #3
0
 def test_tuple(self):
     lsts = (
         ((), "()"),
         ((1, 2), "(1, 2)"),
         ((1, 'a'), "(1, 'a')")
     )
     for obj, s in lsts:
         self.assertEqual(objstr(obj), s)
예제 #4
0
 def do_print(obj, stream):
     if self.custom_printer is not None:
         self.custom_printer(obj)
     else:
         if type(obj) is str:
             print(obj, file=stream)
         else:
             print(objstr(obj), file=stream)
예제 #5
0
 def test_list(self):
     lsts = (
         ([], "[]"),
         ([1, 2], "[1, 2]"),
         ([1, 'a'], "[1, 'a']"),
         ([123, 'a' * 100], f"[\n  123,\n  '{'a' * 100}'\n]")
     )
     for obj, s in lsts:
         self.assertEqual(objstr(obj), s)
예제 #6
0
 def test_get_ellipsis(self):
     self.assertEqual("<C ... >", objstr(C(), 5))
예제 #7
0
 def test_one_line_object(self):
     s = io.StringIO()
     self.assertNotIn("\n", objstr(s))
예제 #8
0
 def test_full_match(self):
     f = ObjTest({"give": "strGive", "curve": "strCurve", "head": "strHead"})
     actual = objstr(f, include=['.*e'])
     self.assertIn("give", actual)
     self.assertIn("curve", actual)
     self.assertNotIn("head", actual)
예제 #9
0
 def test_multiline(self):
     n = ObjTest({"name": "Apple", "age": 10})
     m = ObjTest({"lst": [1, 2, n]})
     actual = objstr(m)
     self.assertEqual(actual.count("\n"), 9)
예제 #10
0
 def do_print(obj, stream):
     if type(obj) is str:
         print(obj, file=stream)
     else:
         print(objstr(obj), file=stream)
예제 #11
0
 def test_wo_attr(self):
     e = random._random.Random()
     actual = objstr(e)
     self.assertTrue(len(actual) > 0)
예제 #12
0
 def test_exclude(self):
     t = InExclude()
     expected = "<InExclude\n  .a = 'in'\n>"
     self.assertEqual(objstr(t, exclude=['b', 'c']), expected)
예제 #13
0
 def test_get_ellipsis(self):
     obj = ObjTest({})
     self.assertEqual("<ObjTest ... >", objstr(obj, 5))
예제 #14
0
 def test_add_match(self):
     t = ObjTest({"xyz": "xyzVal", "xyzz": "xyzzVal", "xyzxz": "xyzxzVal"})
     actual = objstr(t, include=['xyz+'])
     self.assertIn("xyz", actual)
     self.assertIn("xyzz", actual)
     self.assertNotIn("xyzxz", actual)
예제 #15
0
 def test_None(self):
     self.assertEqual('None', objstr(None))
예제 #16
0
 def test_function_type(self):
     self.assertEqual("<function run>", objstr(Car.run))
예제 #17
0
 def test_function_type(self):
     def run(self):
         print("my car can run!")
     obj = ObjTest({"brand": "a", "function": run})
     self.assertEqual("<function run>", objstr(obj.function))
예제 #18
0
 def test_multiline(self):
     m = Multiline()
     actual = objstr(m)
     self.assertEqual(actual.count("\n"), 9)
예제 #19
0
 def test_exclude_indent(self):
     t = ObjTest({"pos1": "in", "pos2": "out", "pos3": "ex"})
     expected = "<ObjTest\n    .pos1 = 'in'\n  >"
     self.assertEqual(objstr(t, indent_level=1, exclude=['pos2', 'pos3']), expected)
예제 #20
0
 def test_str(self):
     s = objstr(A())
     self.assertTrue(len(s) > 0)
예제 #21
0
 def test_include_exclude_mix(self):
     t = ObjTest({"pos1": "in", "pos2": "out", "pos3": "ex"})
     output = objstr(t, include=['pos1', 'pos2'], exclude=['pos2', 'pos3'])
     self.assertIn("pos1", output)
     self.assertNotIn("pos2", output)
     self.assertNotIn("pos3", output)