def test_dir(): assert pformat(vars(Foo())) == ( "{\n" " 'b': 2,\n" " 'c': 3,\n" "}" )
def test_instance_dict(): assert pformat(Foo().__dict__) == ( "{\n" " 'b': 2,\n" " 'c': 3,\n" "}" )
def test_asyncpg_record(): r = Record({'a': 0, 'b': 1}, (41, 42)) assert dict(r) == {'a': 41, 'b': 42} assert pformat(r) == ("<Record({\n" " 'a': 41,\n" " 'b': 42,\n" "})>")
def test_counter(): c = Counter() c['x'] += 1 c['x'] += 1 c['y'] += 1 v = pformat(c) assert v == """\
def test_deep_objects(): f = namedtuple('Foobar', ['foo', 'bar', 'spam']) v = pformat(((f('x', 'y', OrderedDict([(1, 2), (3, 4), (5, 6)])), frozenset(range(3)), [1, 2, { 1: 2 }]), {1, 2, 3})) print(v) assert v == """\
def test_cimultidict(): v = pformat(CIMultiDict({'a': 1, 'b': 2})) assert set(v.split('\n')) == { "<CIMultiDict({", " 'a': 1,", " 'b': 2,", "})>", }
def test_dict(): v = pformat({1: 2, 3: 4}) print(v) assert v == ( '{\n' ' 1: 2,\n' ' 3: 4,\n' '}')
def test_generator(): v = pformat((i for i in range(3))) assert v == ( '(\n' ' 0,\n' ' 1,\n' ' 2,\n' ')')
def test_named_tuple(): f = namedtuple('Foobar', ['foo', 'bar', 'spam']) v = pformat(f('x', 'y', 1)) assert v == ("Foobar(\n" " foo='x',\n" " bar='y',\n" " spam=1,\n" ")")
def test_set(): v = pformat(set(range(5))) assert v == ('{\n' ' 0,\n' ' 1,\n' ' 2,\n' ' 3,\n' ' 4,\n' '}')
def test_tuple(): v = pformat(tuple(range(5))) assert v == ('(\n' ' 0,\n' ' 1,\n' ' 2,\n' ' 3,\n' ' 4,\n' ')')
def test_dataclass(): @dataclass class FooDataclass: x: int y: List[int] f = FooDataclass(123, [1, 2, 3, 4]) v = pformat(f) print(v) assert v == """\
def test_list(): v = pformat(list(range(6))) assert v == ('[\n' ' 0,\n' ' 1,\n' ' 2,\n' ' 3,\n' ' 4,\n' ' 5,\n' ']')
def test_multidict(): d = MultiDict({'a': 1, 'b': 2}) d.add('b', 3) v = pformat(d) assert set(v.split('\n')) == { "<MultiDict({", " 'a': 1,", " 'b': 2,", " 'b': 3,", "})>", }
def test_dictlike(): class Dictlike: _d = {'x': 4, 'y': 42, 3: None} def items(self): yield from self._d.items() def __getitem__(self, item): return self._d[item] assert pformat(Dictlike()) == ("<Dictlike({\n" " 'x': 4,\n" " 'y': 42,\n" " 3: None,\n" "})>")
def check_response(response: 'Response', expected_status: Optional[int]) -> None: if expected_status is None or response.status_code == expected_status: return try: body = pformat(response.json()) except ValueError: body = response.text req = response.request msg = ( f'{req.method} {req.url} returned unexpected status: {response.status_code} (expected {expected_status}), ' f'body:\n{body}') if pytest: # pragma: no branch pytest.fail(msg) else: # pragma: no cover raise ValueError(msg)
def test_sqlalchemy_object(): class User(SQLAlchemyBase): __tablename__ = 'users' id = Column(Integer, primary_key=True) name = Column(String) fullname = Column(String) nickname = Column(String) user = User() user.id = 1 user.name = "Test" user.fullname = "Test For SQLAlchemy" user.nickname = "test" assert pformat(user) == ( "User(\n" " fullname='Test For SQLAlchemy',\n" " id=1,\n" " name='Test',\n" " nickname='test',\n" ")" )
def test_ordered_dict(): v = pformat(OrderedDict([(1, 2), (3, 4), (5, 6)])) print(v) assert v == """\
def test_bytearray_short(): v = pformat(bytearray(b'boo')) assert v == """\
def test_map(): v = pformat(map(str.strip, ['x', 'y ', ' z'])) assert v == """\
def test_filter(): v = pformat(filter(None, [1, 2, False, 3])) assert v == """\
def test_colours(): v = pformat({1: 2, 3: 4}, highlight=True) assert v.startswith('\x1b'), repr(v) v2 = strip_ansi(v) assert v2 == pformat({1: 2, 3: 4}), repr(v2)
def test_os_environ(): v = pformat(os.environ) assert v.startswith('<_Environ({') for key in os.environ: assert f" '{key}': " in v
def test_dict_type(): assert pformat(type({1: 2})) == "<class 'dict'>"
def test_class_dict(): s = pformat(Foo.__dict__) assert s.startswith('<mappingproxy({\n') assert " '__module__': 'tests.test_prettier',\n" in s assert " 'a': 1,\n" in s assert s.endswith('})>')
def test_os_environ(): v = pformat(os.environ) assert v.startswith('<_Environ({') assert " 'HOME': '" in v
def test_short_bytes(): assert "b'abcdefghijklmnopqrstuvwxyz'" == pformat( string.ascii_lowercase.encode())
def test_call_args_py354(): m = MagicMock() m(1, 2, 3, a=4) v = pformat(m.call_args) assert v == """\
def test_indent_numpy_short(): v = pformat({'numpy test': numpy.array(range(10))}) assert v == """{
def test_frozenset(): v = pformat(frozenset(range(3))) print(v) assert v == """\