Skip to content

Commit

Permalink
100% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Jul 5, 2018
1 parent e4064cc commit 573d8dc
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/nti/externalization/datetime.py
Expand Up @@ -93,10 +93,9 @@ def _local_tzinfo(local_tzname=None):
if not tzinfo:
# well nuts. Do the best we can with the current info
# First, get the timezone name, using daylight name if appropriate
if time.daylight and time.altzone is not None and time.tzname[1]:
offset = time.altzone
else:
offset = time.timezone
offset = (time.altzone
if time.daylight and time.altzone is not None and time.tzname[1]
else time.timezone)

add = '+' if offset > 0 else ''
local_tzname = 'Etc/GMT' + add + str((offset // 60 // 60))
Expand Down
2 changes: 1 addition & 1 deletion src/nti/externalization/externalization/externalizer.py
Expand Up @@ -193,7 +193,7 @@ def _obj_has_usable_externalObject(obj):
if has_ext_obj:
ext_ignored = getattr(kind, '__ext_ignore_toExternalObject__', None)
answer = not ext_ignored
if ext_ignored is not None:
if ext_ignored is not None: # pragma: no cover
warnings.warn("The type %r still has __ext_ignore_toExternalObject__. "
"Remove it and toExternalObject()." % (kind,),
FutureWarning)
Expand Down
2 changes: 1 addition & 1 deletion src/nti/externalization/externalization/standard_fields.py
Expand Up @@ -8,6 +8,7 @@
from __future__ import division
from __future__ import print_function

# pylint:disable=inconsistent-return-statements

from calendar import timegm as dt_tuple_to_unix

Expand All @@ -25,7 +26,6 @@
def datetime_to_unix_time(dt):
if dt is not None:
return dt_tuple_to_unix(dt.utctimetuple())
return None


_LAST_MOD_FIELDS = (
Expand Down
16 changes: 16 additions & 0 deletions src/nti/externalization/tests/test_externalization.py
Expand Up @@ -526,6 +526,15 @@ class X(object):
assert_that(ex_dic,
has_entry(StandardExternalFields.CREATED_TIME, is_(Number)))


def test_stand_ext_props(self):
self.assertIn(StandardExternalFields.CREATED_TIME,
StandardExternalFields.EXTERNAL_KEYS)


self.assertIn('CREATED_TIME',
StandardExternalFields.ALL)

def test_to_stand_dict_merges(self):
obj = {}
result = to_standard_external_dictionary(obj, mergeFrom={'abc': 42})
Expand Down Expand Up @@ -555,6 +564,13 @@ def toExternalList(self):
def test_sequence_of_primitives(self):
assert_that(toExternalObject([42]), is_([42]))

def test_mapping_of_non_primitives(self):
class Foo(object):
def toExternalObject(self, **kwargs):
return 42
assert_that(toExternalObject({'key': Foo()}),
is_({'key': 42}))

def test_decorate_callback(self):
# decorate_callback doesn't make much sense.
calls = []
Expand Down
20 changes: 19 additions & 1 deletion src/nti/externalization/tests/test_persistence.py
Expand Up @@ -117,7 +117,7 @@ class P(object):

assert_that(getPersistentState(P), is_(persistent.CHANGED))

def test_with_proxy(self):
def test_with_proxy_p_changed(self):
from zope.proxy import ProxyBase
class P(object):
_p_state = persistent.UPTODATE
Expand All @@ -136,6 +136,24 @@ def _p_changed(self):

setPersistentStateChanged(proxy) # Does nothing

def test_with_proxy_p_state(self):
from zope.proxy import ProxyBase
class P(object):
_p_state = persistent.CHANGED
_p_jar = None

class MyProxy(ProxyBase):

@property
def _p_state(self):
raise AttributeError()

proxy = MyProxy(P())
assert_that(getPersistentState(proxy), is_(persistent.CHANGED))

setPersistentStateChanged(proxy) # Does nothing


class TestWeakRef(unittest.TestCase):

def test_to_externalObject(self):
Expand Down

0 comments on commit 573d8dc

Please sign in to comment.