Issue2790

classification
Title: Equivalent signal handlers do not test equal using ==
Type: behaviour Severity: normal
Components: Library Versions: Jython 2.7
Milestone:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: jeff.allen
Priority: normal Keywords: test failure causes

Created on 2019-08-01.07:31:14 by jeff.allen, last changed 2019-08-01.07:31:14 by jeff.allen.

Messages
msg12614 (view) Author: Jeff Allen (jeff.allen) Date: 2019-08-01.07:31:14
test_signal.BasicSignalTests.test_getsignal has been failing for a while, so I have looked into the reason why two values that look the same are not reported as equal:

     [exec] FAIL: test_getsignal (test.test_signal.BasicSignalTests)
     [exec] ----------------------------------------------------------------------
     [exec] Traceback (most recent call last):
     [exec]   File "/home/travis/build/jeff5/jython/dist/Lib/test/test_signal.py", line 216, in test_getsignal
     [exec]     self.assertEquals(signal.getsignal(signal.SIGHUP), hup)
     [exec] AssertionError: java.lang.Terminator$1@3ce1ca45 != java.lang.Terminator$1@3ce1ca45

The test that produces this runs:

    def test_getsignal(self):
        hup = signal.signal(signal.SIGHUP, self.trivial_signal_handler)
        self.assertEquals(signal.getsignal(signal.SIGHUP),
                          self.trivial_signal_handler)
        signal.signal(signal.SIGHUP, hup)
        self.assertEquals(signal.getsignal(signal.SIGHUP), hup)

and it is the second assertEquals that fails.

The objects in question are different Java objects, both Signal$SunMiscHandler, and proxied by a PyObjectDerived. __eq__ delegates to the proxied objects' comparison, which is Object.equals, and therefore we end up testing object identity. The second call to signal.signal, to re-install the original handler hup, creates a distinct Signal$SunMiscHandler, hence the problem. Its (private) fields are the same, so it has the intended effect, and its toString looks just like the original. But == still yields False.

I will skip this test for now, with a reference to this issue.

Our implementation of signal (see #1074) is somewhat incomplete, and a lot of test_signal is disabled anyway. The present issue is bounded to the __eq__ issue. A general overhaul of signal may be in order, but a point fix would do. (Not marking this for 2.7.2.)
History
Date User Action Args
2019-08-01 07:31:14jeff.allencreate