Merge lp:~openerp-community-testers/openobject-server/trunk-sequences-test-bug-1083724 into lp:openobject-server

Proposed by Georges Racinet
Status: Needs review
Proposed branch: lp:~openerp-community-testers/openobject-server/trunk-sequences-test-bug-1083724
Merge into: lp:openobject-server
Diff against target: 33 lines (+15/-8)
1 file modified
openerp/tests/test_ir_sequence.py (+15/-8)
To merge this branch: bzr merge lp:~openerp-community-testers/openobject-server/trunk-sequences-test-bug-1083724
Reviewer Review Type Date Requested Status
Vo Minh Thu (community) Needs Information
Review via email: mp+136489@code.launchpad.net

Description of the change

Checking the error code. This pattern of a posteriori checking of the exception arguments after using self.assertRaises as a context manager is actually inspired by python documentation (http://docs.python.org/dev/library/unittest.html#unittest.TestCase.assertRaises)

Also now cursor closing occurs in a finally: statement to avoid blocking besides failing

To post a comment you must log in.
Revision history for this message
Vo Minh Thu (thu) wrote :

Hi!

Indeed, the

  with ... as raise_ctx:

seems nice.

But the diff seems messed up by tabs.

And I don't understand the try/finally. Don't you want to put all the code using the cursors in the try body?

review: Needs Information
Revision history for this message
Vo Minh Thu (thu) wrote :

(Please put back the merge prop to 'need review' if necessary.)

Revision history for this message
Georges Racinet (gracinet) wrote :

Ah yes, sorry about the tabs, I worked on it directly on a dumb server.

About the try/finally, I thought that afterwards, too.

Note that most tests from that module should have their cursor closing similarly protected, as well.

Revision history for this message
Georges Racinet (gracinet) wrote :

Should be better, now.

I confirm that cursor treatment could really be improved in these tests:
  - no protection against failures, and we've seen that can leave locks behind
  - commits !

I imagine things could be really improved by subclassing TransactionCase (which I guess is more recent) except for these draw_twice.

But that should be a separate issue.

Unmerged revisions

4604. By Georges Racinet <email address hidden>

A wider try/finally in test draw_twice (no gap)

4603. By Georges Racinet <email address hidden>

Getting rid of tabs, plus one pyflakes error

4602. By Georges Racinet <email address hidden>

[FIX] Proper checking of pg error code for expected lock fail in test

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/tests/test_ir_sequence.py'
2--- openerp/tests/test_ir_sequence.py 2012-11-28 13:51:01 +0000
3+++ openerp/tests/test_ir_sequence.py 2012-11-29 13:45:30 +0000
4@@ -110,14 +110,21 @@
5 """
6 cr0 = cursor()
7 cr1 = cursor()
8- cr1._default_log_exceptions = False # Prevent logging a traceback
9- msg_re = '^could not obtain lock on row in relation "ir_sequence"$'
10- with self.assertRaisesRegexp(psycopg2.OperationalError, msg_re):
11- n0 = registry('ir.sequence').next_by_code(cr0, ADMIN_USER_ID, 'test_sequence_type_2', {})
12- assert n0
13- n1 = registry('ir.sequence').next_by_code(cr1, ADMIN_USER_ID, 'test_sequence_type_2', {})
14- cr0.close()
15- cr1.close()
16+ try:
17+ cr1._default_log_exceptions = False # Prevent logging a traceback
18+ with self.assertRaises(psycopg2.OperationalError) as raise_ctx:
19+ n0 = registry('ir.sequence').next_by_code(cr0, ADMIN_USER_ID, 'test_sequence_type_2', {})
20+ assert n0
21+ registry('ir.sequence').next_by_code(cr1, ADMIN_USER_ID, 'test_sequence_type_2', {})
22+
23+ exc = raise_ctx.exception
24+ self.assertEquals(exc.pgcode,
25+ psycopg2.errorcodes.LOCK_NOT_AVAILABLE,
26+ "Unexpected PostgreSQL Error instead of "
27+ "expected LOCK_NOT_AVAILABLE :" + exc.pgerror)
28+ finally:
29+ cr0.close()
30+ cr1.close()
31
32 @classmethod
33 def tearDownClass(cls):