[issue43273] Mock `_mock_wraps` is undocumented and inconsistently named

2021-02-20 Thread Richard Wise


New submission from Richard Wise :

I am trying to use wraps to delegate a call to a decorated patch mock to 
another method. By examining the source code, I was able to achieve this using 
the (apparently undocumented) `Mock._mock_wraps` attribute instead of the 
`wraps` attribute which would be expected given the constructor parameter 
names. I find this behaviour very confusing and inconsistent. Can we either 
expose `Mock.wraps` attribute or document `_mock_wraps` accordingly?

Example:

class MockRepro(unittest.TestCase)

@patch('foo')
def test_side_effect(self, mock_foo):
  # Set side effect in constructor as per 
https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock 
  Mock(side_effect = [1, 2])
  # Or can set on decorated patch
  foo.side_effect = [1, 2]

@patch('foo')
def test_wraps(self, mock_foo):
  def wrapped_method():
return 3
  # Set wraps in constructor as per 
https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock 
  Mock(wraps=wrapped_method)
  # Or can set on decorated patch
  foo.wraps = wrapped_method # This silently fails
  foo._mock_wraps = wrapped_method # Where does `_mock_wraps` come from?

--
components: Library (Lib)
messages: 387397
nosy: Woodz
priority: normal
severity: normal
status: open
title: Mock `_mock_wraps` is undocumented and inconsistently named
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue43273>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43237] datetime.__eq__ returns true when timezones don't match

2021-02-15 Thread Richard Wise


New submission from Richard Wise :

from datetime import datetime, timezone, timedelta

datetime_in_sgt = datetime(2021, 2, 16, 8, 0, 0, 
tzinfo=timezone(timedelta(hours=8)))
datetime_in_utc = datetime(2021, 2, 16, 0, 0, 0, tzinfo=timezone.utc)

print(datetime_in_sgt == datetime_in_utc)

Expected: False
Actual: True

Although these two datetimes represent the same instant on the timeline, they 
are not identical because they use different timezones. This means that when 
unit testing timezone handling, tests will incorrectly pass despite data being 
returned in UTC instead of the requested timezone, so we need to write code 
such as this:

# Timestamp comparison
self.assertEqual(datetime_in_sgt, datetime_in_utc)
# Timezone comparison
self.assertEqual(datetime_in_sgt.tzinfo, datetime_in_utc.tzinfo)

This is confusing and non-intuitive.

For examples of how other languages handle such comparison, can refer to: 
https://docs.oracle.com/javase/8/docs/api/java/time/ZonedDateTime.html#equals-java.lang.Object-
 and 
https://docs.oracle.com/javase/8/docs/api/java/time/Instant.html#equals-java.lang.Object-

--
components: Library (Lib)
messages: 387087
nosy: Woodz
priority: normal
severity: normal
status: open
title: datetime.__eq__ returns true when timezones don't match
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue43237>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com