예제 #1
0
def test_dir():
    assert pformat(vars(Foo())) == (
        "{\n"
        "    'b': 2,\n"
        "    'c': 3,\n"
        "}"
    )
예제 #2
0
def test_instance_dict():
    assert pformat(Foo().__dict__) == (
        "{\n"
        "    'b': 2,\n"
        "    'c': 3,\n"
        "}"
    )
예제 #3
0
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"
                          "})>")
예제 #4
0
def test_counter():
    c = Counter()
    c['x'] += 1
    c['x'] += 1
    c['y'] += 1
    v = pformat(c)
    assert v == """\
예제 #5
0
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 == """\
예제 #6
0
def test_cimultidict():
    v = pformat(CIMultiDict({'a': 1, 'b': 2}))
    assert set(v.split('\n')) == {
        "<CIMultiDict({",
        "    'a': 1,",
        "    'b': 2,",
        "})>",
    }
예제 #7
0
def test_dict():
    v = pformat({1: 2, 3: 4})
    print(v)
    assert v == (
        '{\n'
        '    1: 2,\n'
        '    3: 4,\n'
        '}')
예제 #8
0
def test_generator():
    v = pformat((i for i in range(3)))
    assert v == (
        '(\n'
        '    0,\n'
        '    1,\n'
        '    2,\n'
        ')')
예제 #9
0
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"
                 ")")
예제 #10
0
def test_set():
    v = pformat(set(range(5)))
    assert v == ('{\n'
                 '    0,\n'
                 '    1,\n'
                 '    2,\n'
                 '    3,\n'
                 '    4,\n'
                 '}')
예제 #11
0
def test_tuple():
    v = pformat(tuple(range(5)))
    assert v == ('(\n'
                 '    0,\n'
                 '    1,\n'
                 '    2,\n'
                 '    3,\n'
                 '    4,\n'
                 ')')
예제 #12
0
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 == """\
예제 #13
0
def test_list():
    v = pformat(list(range(6)))
    assert v == ('[\n'
                 '    0,\n'
                 '    1,\n'
                 '    2,\n'
                 '    3,\n'
                 '    4,\n'
                 '    5,\n'
                 ']')
예제 #14
0
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,",
        "})>",
    }
예제 #15
0
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"
                                   "})>")
예제 #16
0
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)
예제 #17
0
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"
        ")"
    )
예제 #18
0
def test_ordered_dict():
    v = pformat(OrderedDict([(1, 2), (3, 4), (5, 6)]))
    print(v)
    assert v == """\
예제 #19
0
def test_bytearray_short():
    v = pformat(bytearray(b'boo'))
    assert v == """\
예제 #20
0
def test_map():
    v = pformat(map(str.strip, ['x', 'y ', ' z']))
    assert v == """\
예제 #21
0
def test_filter():
    v = pformat(filter(None, [1, 2, False, 3]))
    assert v == """\
예제 #22
0
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)
예제 #23
0
def test_os_environ():
    v = pformat(os.environ)
    assert v.startswith('<_Environ({')
    for key in os.environ:
        assert f"    '{key}': " in v
예제 #24
0
def test_dict_type():
    assert pformat(type({1: 2})) == "<class 'dict'>"
예제 #25
0
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('})>')
예제 #26
0
def test_os_environ():
    v = pformat(os.environ)
    assert v.startswith('<_Environ({')
    assert "    'HOME': '" in v
예제 #27
0
def test_short_bytes():
    assert "b'abcdefghijklmnopqrstuvwxyz'" == pformat(
        string.ascii_lowercase.encode())
예제 #28
0
def test_call_args_py354():
    m = MagicMock()
    m(1, 2, 3, a=4)
    v = pformat(m.call_args)

    assert v == """\
예제 #29
0
def test_indent_numpy_short():
    v = pformat({'numpy test': numpy.array(range(10))})
    assert v == """{
예제 #30
0
def test_frozenset():
    v = pformat(frozenset(range(3)))
    print(v)
    assert v == """\