From aa8f34dbfc87e18f7f7344ea19862fac6ae8d541 Mon Sep 17 00:00:00 2001 From: Jay Marcyes Date: Thu, 27 Dec 2018 02:41:29 -0700 Subject: [PATCH] v0.8.1. All tests are passing. So this closes #36 and closes #31 --- pout/__init__.py | 10 +--------- pout/environ.py | 2 ++ pout/interface.py | 14 ------------- pout/value.py | 11 +++++++++-- pout_test/pout_test.py | 45 +++++++++++++++--------------------------- 5 files changed, 28 insertions(+), 54 deletions(-) diff --git a/pout/__init__.py b/pout/__init__.py index 6bbc680..1a19684 100644 --- a/pout/__init__.py +++ b/pout/__init__.py @@ -61,7 +61,7 @@ ) -__version__ = '0.8.0' +__version__ = '0.8.1' # This is the standard logger for debugging pout itself, if it hasn't been @@ -71,7 +71,6 @@ # http://stackoverflow.com/questions/6333916/python-logging-ensure-a-handler-is-added-only-once if len(logger.handlers) == 0: logger.setLevel(logging.WARNING) - #logger.setLevel(logging.ERROR) logger.addHandler(logging.NullHandler()) @@ -123,13 +122,6 @@ def v(*args, **kwargs): if not args: raise ValueError("you didn't pass any arguments to print out") - #frame = inspect.currentframe() -# frames = inspect.stack() -# frame = frames[0] -# modname = inspect.getmodule(frame[0]).__name__ -# funcname = frame[0].f_code.co_name -# print("{}:{} {} {}.{}".format(frame[1], frame[2], frame[4], modname, funcname)) - with Reflect.context(args, **kwargs) as r: instance = V_CLASS(r, stream, **kwargs) instance() diff --git a/pout/environ.py b/pout/environ.py index c2d7e01..e12b337 100644 --- a/pout/environ.py +++ b/pout/environ.py @@ -9,6 +9,8 @@ ENCODING = os.environ.get("POUT_ENCODING", "UTF-8") ENCODING_REPLACE = os.environ.get("POUT_ENCODING_REPLACE", "pout.replace") +OBJECT_DEPTH = int(os.environ.get("POUT_OBJECT_DEPTH", 4)) + def handle_decode_replace(cls, e): """this handles replacing bad characters when printing out diff --git a/pout/interface.py b/pout/interface.py index 45b3273..a98c9a2 100644 --- a/pout/interface.py +++ b/pout/interface.py @@ -116,8 +116,6 @@ def _str(self, name, val): except (TypeError, KeyError, AttributeError) as e: logger.warning(e, exc_info=True) - - else: s = "{} = {}".format(name, self._str_val(val)) else: @@ -149,7 +147,6 @@ def value(self): class ValueInterface(BaseInterface): - def name_value(self): call_info = self.reflect.info args = ["{}\n\n".format(self._str(v['name'], v['val'])) for v in call_info['args']] @@ -160,17 +157,6 @@ def value(self): args = ["{}\n\n".format(self._str(None, v['val'])) for v in call_info['args']] return self._printstr(args) -# def __repr__(self): -# call_info = self.reflect.info -# #pout2.v(call_info) -# args = ["{}\n\n".format(self._str(v['name'], v['val'])) for v in call_info['args']] -# return self._printstr(args, call_info) - -# def value(self): -# """Returns only the value of the passed in args, no context information""" -# call_info = self.reflect.info -# args = ["{}\n\n".format(self._str(None, v['val'])) for v in call_info['args']] -# return self._printstr(args) class HereInterface(BaseInterface): diff --git a/pout/value.py b/pout/value.py index 789d51f..2db5a59 100644 --- a/pout/value.py +++ b/pout/value.py @@ -6,6 +6,7 @@ import os import traceback from collections import KeysView +import logging from .compat import * from . import environ @@ -13,6 +14,9 @@ from .utils import String +logger = logging.getLogger(__name__) + + class Inspect(object): @property @@ -481,8 +485,11 @@ def _getattr(self, val, key, default_val): """wrapper around global getattr(...) method that suppresses any exception raised""" try: ret = getattr(val, key, default_val) - except Exception: + + except Exception as e: + logger.exception(e) ret = default_val + return ret def _get_name(self, val, src_file, default='Unknown'): @@ -565,7 +572,7 @@ def __repr__(self): s += repr(Value(val.__pout__())) else: - if depth < 4: + if depth < environ.OBJECT_DEPTH: s += "\n<" s_body = '' diff --git a/pout_test/pout_test.py b/pout_test/pout_test.py index 5e78f99..dda6f3c 100644 --- a/pout_test/pout_test.py +++ b/pout_test/pout_test.py @@ -171,35 +171,6 @@ class Module(object): pass del self.issue_module del self.issue_fields - def test__get_name(self): - """makes sure if __getattr__ raises other errors than AttributeError then - pout will still print correctly""" - class FooGetName(object): - def __init__(self): - self.fields = {} - def __getattr__(self, key): - # This will raise a KeyError when key doesn't exist - return self.fields[key] - - with testdata.capture() as c: - fgn = FooGetName() - pout.v(fgn) - for s in ["pout_test.FooGetName", "id:", "path:", "Ancestry:", "__str__:", "fields = "]: - self.assertTrue(s in c, s) - - def test_find_call_depth(self): - s = "foo" - class PoutChild(pout.Pout): - def v(self, *args): - self._printstr("PoutChild") - super(PoutChild, self).v(*args) - - pout.pout_class = PoutChild - with testdata.capture() as c: - pout.v(s) - self.assertTrue('s (3) = "foo"' in c) - pout.pout_class = pout.Pout - def test__get_arg_info(self): foo = 1 with testdata.capture() as c: @@ -391,6 +362,22 @@ def test_ss_return(self): class VTest(unittest.TestCase): + def test_get_name(self): + """makes sure if __getattr__ raises other errors than AttributeError then + pout will still print correctly""" + class FooGetName(object): + def __init__(self): + self.fields = {} + def __getattr__(self, key): + # This will raise a KeyError when key doesn't exist + return self.fields[key] + + with testdata.capture() as c: + fgn = FooGetName() + pout.v(fgn) + for s in ["pout_test.FooGetName", "id:", "path:", "Ancestry:", "__str__:", "fields = "]: + self.assertTrue(s in c, s) + def test_vs(self): with testdata.capture() as c: d = {'foo': 1, 'bar': 2}