Beispiel #1
0
 def test_idr_truncates_list(self):
     idr = IndentedRepr()
     idr.maxlist = 5
     obj = [list(range(6))]
     expected = """\
     [
       [
         0,
         1,
         2,
         3,
         4,
         ...
       ]
     ]"""
     expected = textwrap.dedent(expected)
     assert idr.repr(obj) == expected
Beispiel #2
0
    def test_idr_toplevel_untruncated(self):
        idr = IndentedRepr()
        idr.maxlist = 5
        obj = list(range(10))
        expected = """\
        [
          0,
          1,
          2,
          3,
          4,
          5,
          6,
          7,
          8,
          9
        ]"""
        expected = textwrap.dedent(expected)
        assert idr.repr(obj) == expected

        idr.maxdict = 5
        obj = {i: i for i in range(10)}

        expected = """\
        {
          0: 0,
          1: 1,
          2: 2,
          3: 3,
          4: 4,
          5: 5,
          6: 6,
          7: 7,
          8: 8,
          9: 9
        }"""
        expected = textwrap.dedent(expected)
        assert idr.repr(obj) == expected
Beispiel #3
0
    def test_untruncated(self):
        long_idr = IndentedRepr()
        long_idr.maxlevel = 100
        long_idr.maxdict = 100
        long_idr.maxlist = 100
        long_idr.maxtuple = 100
        long_idr.maxset = 100
        long_idr.maxfrozenset = 100
        long_idr.maxdeque = 100
        long_idr.maxarray = 100
        long_idr.maxlong = 100
        long_idr.maxstring = 100
        long_idr.maxother = 100

        # dict
        obj = [{i: i for i in range(10)}]
        assert untruncated_idr.repr(obj) == long_idr.repr(obj)
        # list
        obj = [list(range(50))]
        assert untruncated_idr.repr(obj) == long_idr.repr(obj)
        # tuple
        obj = [tuple(range(50))]
        assert untruncated_idr.repr(obj) == long_idr.repr(obj)
        # set
        obj = [frozenset(range(50))]
        assert untruncated_idr.repr(obj) == long_idr.repr(obj)
        # long
        obj = int("".join(str(x) for x in range(50)))
        assert untruncated_idr.repr(obj) == long_idr.repr(obj)
        # string
        obj = "".join(random.choice(string.ascii_letters) for i in range(50))
        assert untruncated_idr.repr(obj) == long_idr.repr(obj)
Beispiel #4
0
 def test_idr_truncates_level(self):
     idr = IndentedRepr()
     idr.maxlevel = 3
     obj = [[[[True]]]]
     expected = "[[[[...]]]]"
     assert idr.repr(obj) == expected
Beispiel #5
0
 def test_idr_truncates_str(self):
     idr = IndentedRepr()
     idr.maxstring = 8
     s = "abcdefghijkl"
     assert idr.repr(s) == "'a...kl'"
Beispiel #6
0
 def test_idr_truncates_level(self):
     idr = IndentedRepr()
     idr.maxlevel = 3
     obj = [[[[True]]]]
     expected = "[[[[...]]]]"
     self.assertEqual(idr.repr(obj), expected)
Beispiel #7
0
 def test_idr_truncates_str(self):
     idr = IndentedRepr()
     idr.maxstring = 8
     s = "abcdefghijkl"
     self.assertEqual(idr.repr(s), "'a...kl'")