Skip to content

Commit 8561fca

Browse files
committed
Add pprint utility method to the VerboseEcho class
The `.verbosity` attribute of the AnnotationConfig class should not be accessed directly, otherwise some tests that use FakeConfig will fail.
1 parent 8fad04f commit 8561fca

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

code_annotations/base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import datetime
55
import errno
66
import os
7-
import pprint
87
import re
98
from abc import ABCMeta, abstractmethod
109

@@ -416,8 +415,7 @@ def check_results(self, all_results):
416415
Returns:
417416
Boolean indicating whether or not any errors were found
418417
"""
419-
if self.config.verbosity >= 2:
420-
pprint.pprint(all_results, indent=3)
418+
self.echo.pprint(all_results, indent=3, verbosity_level=2)
421419

422420
group_children = self._get_group_children()
423421

code_annotations/find_django.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44
import inspect
55
import os
6-
import pprint
76
import sys
87

98
import django
@@ -89,7 +88,7 @@ def list_local_models(self):
8988
self.echo(
9089
'Listing {} local models requiring annotations:'.format(len(self.local_models))
9190
)
92-
pprint.pprint(sorted([self.get_model_id(model) for model in self.local_models]), indent=4)
91+
self.echo.pprint(sorted([self.get_model_id(model) for model in self.local_models]), indent=4)
9392
else:
9493
self.echo('No local models requiring annotations.')
9594

code_annotations/helpers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import os
55
import re
66
import sys
7+
from io import StringIO
8+
from pprint import pprint
79

810
import click
911

@@ -91,6 +93,15 @@ def echo_vvv(self, output, **kwargs):
9193
"""
9294
self.echo(output, 3, **kwargs)
9395

96+
def pprint(self, data, indent=4, verbosity_level=0):
97+
"""
98+
Pretty-print some data with the given verbosity level.
99+
"""
100+
formatted = StringIO()
101+
pprint(data, indent=indent, stream=formatted)
102+
formatted.seek(0)
103+
self.echo(formatted.read(), verbosity_level=verbosity_level)
104+
94105

95106
def clean_abs_path(filename_to_clean, parent_path):
96107
"""

0 commit comments

Comments
 (0)