diff options
author | John L. Villalovos <john@sodarock.com> | 2022-01-07 12:12:24 -0800 |
---|---|---|
committer | John L. Villalovos <john@sodarock.com> | 2022-01-07 12:12:24 -0800 |
commit | e34a2e28f2aee2ab3314927bb51891b6ace78908 (patch) | |
tree | fc331ea13daca0b10d95174a861f50c4855906e0 /tests | |
parent | 989634055b0c5ab622ac7774b546928a564a31ef (diff) | |
download | gitlab-jlvillal/pprint.tar.gz |
chore: add `pprint()` and `pformat()` methods to RESTObjectjlvillal/pprint
This is useful in debugging and testing. As can easily print out the
values from an instance in a more human-readable form.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/test_base.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/unit/test_base.py b/tests/unit/test_base.py index 3ca0206..eec6af0 100644 --- a/tests/unit/test_base.py +++ b/tests/unit/test_base.py @@ -201,3 +201,25 @@ class TestRESTObject: obj1 = FakeObject(fake_manager, {"attr1": "foo"}) obj2 = FakeObject(fake_manager, {"attr1": "bar"}) assert obj1 != obj2 + + def test_dunder_str(self, fake_manager): + obj1 = FakeObject(fake_manager, {"attr1": "foo"}) + assert str(obj1) == ( + "<class 'tests.unit.test_base.FakeObject'> => {'attr1': 'foo'}" + ) + + def test_pformat(self, fake_manager): + obj1 = FakeObject(fake_manager, {"attr1": "foo"}) + assert obj1.pformat() == ( + "<class 'tests.unit.test_base.FakeObject'> => \n{'attr1': 'foo'}" + ) + + def test_pprint(self, capfd, fake_manager): + obj1 = FakeObject(fake_manager, {"attr1": "foo"}) + result = obj1.pprint() + assert result is None + stdout, stderr = capfd.readouterr() + assert stdout == ( + "<class 'tests.unit.test_base.FakeObject'> => \n{'attr1': 'foo'}\n" + ) + assert stderr == "" |