Closed myronmarston closed 1 year ago
Also, the build is failing on python 2.6 because I used assertIn
but 2.6 lacks it, apparently. Any suggestions for how to deal with that, @dlecocq?
Dropping 2.6 support is definitely an option. Most people have been adding 3.x support and dropping 2.6 support. You could also specifically depend on unittest2. That will get you the 2.7 unittest support in 2.6.
Dropping 2.6 support is definitely an option. Most people have been adding 3.x support and dropping 2.6 support. You could also specifically depend on unittest2. That will get you the 2.7 unittest support in 2.6.
Being a total newb to python package management, I'm unsure how to depend on unittest2. What would I need to update to get travis to use unittest2?
Another option would be to just implement assertIn
yourself. I know a lot of people have done that to get Python 2.7 asserts in Python 2.6:
def assertIn(self, member, container, msg=None):
"""Just like self.assertTrue(a in b), but with a nicer default message."""
if member not in container:
standardMsg = '%s not found in %s' % (safe_repr(member),
safe_repr(container))
self.fail(self._formatMessage(msg, standardMsg))
Since this isn't actually a Python package, but instead just happens to use Python as the test suite, it probably doesn't make sense to pull in external packages as a dependency. I would probably just do the inline assertIn
implementation.
Another option would be to just implement assertIn yourself. I know a lot of people have done that to get Python 2.7 asserts in Python 2.6:
Thanks, that's helpful. Is there a simple way to conditionally define that only on Python 2.6? (Or only when assertIn
is undefined?)
On Ruby I do that although the time (RSpec has many, many conditional method defs to account for all the ruby versions and interpretters it supports) but I do not understand the python runtime model well enough to know how to do that.
Looks like this works on Python 2.6.9 and 2.7.3:
class FooTest(unittest.TestCase):
if 'assertIn' not in dir(unittest.TestCase):
def assertIn(self, member, container, msg=None):
"""Just like self.assertTrue(a in b), but with a nicer default message."""
from pprint import saferepr
if member not in container:
standardMsg = '%s not found in %s' % (saferepr(member),
saferepr(container))
self.fail(msg if msg else standardMsg)
def test_assertIn(self):
self.assertIn(0, [0])
self.assertIn(1, [0])
if __name__ == '__main__':
unittest.main()
Thank you, @b4hand, that works wonderfully.
This is what I've got so far, @dlecocq. One thing we haven't discussed (which i'd like to chat about) is what to do with all the job records themselves when we delete or merge a queue. The job record has the queue name in it and presumably needs to be updated but I'd really rather not add another O(N) operation to
merge
given how I plan to use it...but maybe there's no way around it.Regardless, I'll get started on adding that, and benchmark it....maybe it won't be so bad.