Skip to content

Commit

Permalink
constructor.timezone: __copy_ & __deepcopy__
Browse files Browse the repository at this point in the history
close #381
  • Loading branch information
ovv committed Apr 6, 2020
1 parent d0d660d commit 6ca6f55
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/yaml/constructor.py
Expand Up @@ -38,6 +38,12 @@ def utcoffset(self, dt=None):
def dst(self, dt=None):
return datetime.timedelta(0)

def __copy__(self):
return self.__deepcopy__()

def __deepcopy__(self, memodict={}):
return self.__class__(self.utcoffset())

__repr__ = __str__ = tzname


Expand Down
12 changes: 12 additions & 0 deletions tests/lib/test_constructor.py
Expand Up @@ -305,6 +305,18 @@ def test_subclass_blacklist_types(data_filename, verbose=False):

test_subclass_blacklist_types.unittest = ['.subclass_blacklist']

def test_timezone_copy(verbose=False):
import copy
tzinfo = yaml.constructor.timezone(datetime.timedelta(0))

tz_copy = copy.copy(tzinfo)
tz_deepcopy = copy.deepcopy(tzinfo)

if tzinfo.tzname() != tz_copy.tzname() != tz_deepcopy.tzname():
raise AssertionError("Timezones should be equal")

test_timezone_copy.unittest = []

if __name__ == '__main__':
import sys, test_constructor
sys.modules['test_constructor'] = sys.modules['__main__']
Expand Down

0 comments on commit 6ca6f55

Please sign in to comment.