| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9896340 commit e34a2e2
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -179,6 +179,17 @@ resources. For example: | |||
| 179 | 179 | project = gl.projects.get(1) | |
| 180 | 180 | project.star() | |
| 181 | 181 | ||
| 182 | + You can print a Gitlab Object. For example: | ||
| 183 | + | ||
| 184 | + .. code-block:: python | ||
| 185 | + | ||
| 186 | + project = gl.projects.get(1) | ||
| 187 | + print(project) | ||
| 188 | + # Or in a prettier format. These two are equivalent. | ||
| 189 | + print(project.pformat()) | ||
| 190 | + project.pprint() | ||
| 191 | + | ||
| 192 | + | ||
| 182 | 193 | Base types | |
| 183 | 194 | ========== | |
| 184 | 195 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,7 @@ | |||
| 16 | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 17 | 17 | ||
| 18 | 18 | import importlib | |
| 19 | + import pprint | ||
| 19 | 20 | import textwrap | |
| 20 | 21 | from types import ModuleType | |
| 21 | 22 | from typing import Any, Dict, Iterable, NamedTuple, Optional, Tuple, Type | |
@@ -147,6 +148,14 @@ def __str__(self) -> str: | |||
| 147 | 148 | data.update(self._updated_attrs) | |
| 148 | 149 | return f"{type(self)} => {data}" | |
| 149 | 150 | ||
| 151 | + def pformat(self) -> str: | ||
| 152 | + data = self._attrs.copy() | ||
| 153 | + data.update(self._updated_attrs) | ||
| 154 | + return f"{type(self)} => \n{pprint.pformat(data)}" | ||
| 155 | + | ||
| 156 | + def pprint(self) -> None: | ||
| 157 | + print(self.pformat()) | ||
| 158 | + | ||
| 150 | 159 | def __repr__(self) -> str: | |
| 151 | 160 | if self._id_attr: | |
| 152 | 161 | return f"<{self.__class__.__name__} {self._id_attr}:{self.get_id()}>" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -201,3 +201,25 @@ def test_inequality_no_id(self, fake_manager): | |||
| 201 | 201 | obj1 = FakeObject(fake_manager, {"attr1": "foo"}) | |
| 202 | 202 | obj2 = FakeObject(fake_manager, {"attr1": "bar"}) | |
| 203 | 203 | assert obj1 != obj2 | |
| 204 | + | ||
| 205 | + def test_dunder_str(self, fake_manager): | ||
| 206 | + obj1 = FakeObject(fake_manager, {"attr1": "foo"}) | ||
| 207 | + assert str(obj1) == ( | ||
| 208 | + "<class 'tests.unit.test_base.FakeObject'> => {'attr1': 'foo'}" | ||
| 209 | + ) | ||
| 210 | + | ||
| 211 | + def test_pformat(self, fake_manager): | ||
| 212 | + obj1 = FakeObject(fake_manager, {"attr1": "foo"}) | ||
| 213 | + assert obj1.pformat() == ( | ||
| 214 | + "<class 'tests.unit.test_base.FakeObject'> => \n{'attr1': 'foo'}" | ||
| 215 | + ) | ||
| 216 | + | ||
| 217 | + def test_pprint(self, capfd, fake_manager): | ||
| 218 | + obj1 = FakeObject(fake_manager, {"attr1": "foo"}) | ||
| 219 | + result = obj1.pprint() | ||
| 220 | + assert result is None | ||
| 221 | + stdout, stderr = capfd.readouterr() | ||
| 222 | + assert stdout == ( | ||
| 223 | + "<class 'tests.unit.test_base.FakeObject'> => \n{'attr1': 'foo'}\n" | ||
| 224 | + ) | ||
| 225 | + assert stderr == "" | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments