Skip to content

Commit

Permalink
v0.8.1. All tests are passing. So this closes #36 and closes #31
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaymon committed Dec 27, 2018
1 parent 83d8341 commit aa8f34d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 54 deletions.
10 changes: 1 addition & 9 deletions pout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())


Expand Down Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions pout/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions pout/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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']]
Expand All @@ -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):
Expand Down
11 changes: 9 additions & 2 deletions pout/value.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
import os
import traceback
from collections import KeysView
import logging

from .compat import *
from . import environ
from .path import Path
from .utils import String


logger = logging.getLogger(__name__)


class Inspect(object):

@property
Expand Down Expand Up @@ -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'):
Expand Down Expand Up @@ -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 = ''

Expand Down
45 changes: 16 additions & 29 deletions pout_test/pout_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit aa8f34d

Please sign in to comment.