[PATCH] even more python patches
Noel Power
nopower at suse.com
Thu Nov 1 10:02:40 UTC 2018
Hi Douglas
On 01/11/2018 00:17, Douglas Bagnall wrote:
>>>> [PATCH 08/17] tests/py/rodc_rwdc: avoid py2/py3 .next compat issues
>>>>
>>>> class RodcRwdcTests(password_lockout_base.BasePasswordTestCase):
>>>> - counter = itertools.count(1).next
>>>> + next_user_number = [1]
>>>>
>>> I didn't get why a list was used for next_user_number, was there some
>>> reason why just a normal variable wouldn't work? Anyway I think if the
>>> orig style of code was to be ported below would be more in line and
>>> *should* (hasn't been tested) work
>> OK, yes, that was a sad hack. The reason a normal variable won't work is
>> each test gets its own instance of the class, and assigning to it will
>> only overlay the class copy with an instance copy, meaning the counter
>> doesn't count.
makes sense
>>
>> I'm going to leave that out right now, because it seems more important
>> that I have lunch than sort it out.
> What I should have said (it came to me at lunch) is that your approach:
lol
>
>
>> @@ -115,7 +115,6 @@ def get_server_ref_from_samdb(samdb):
>>
>>
>> class RodcRwdcCachedTests(password_lockout_base.BasePasswordTestCase):
>> - counter = itertools.count(1).next
>>
>> def _check_account_initial(self, dn):
>> self.force_replication()
>> @@ -686,7 +685,7 @@ class RodcRwdcCachedTests(password_lockout_base.BasePasswordTestCase):
>>
>>
>> class RodcRwdcTests(password_lockout_base.BasePasswordTestCase):
>> - counter = itertools.count(1).next
>> + counter = itertools.count(1,1)
>>
>> def force_replication(self, base=None):
>> if base is None:
>> @@ -982,7 +981,7 @@ class RodcRwdcTests(password_lockout_base.BasePasswordTestCase):
>> self._test_add_modify_delete()
>>
>> def _new_user(self):
>> - username = "u%sX%s" % (self.tag[:12], self.counter())
>> + username = "u%sX%s" % (self.tag[:12], next(self.counter()))
>> password = 'password#1'
>> dn = 'CN=%s,CN=Users,%s' % (username, self.base_dn)
>> o = {
>>
> should work and is probably best. Could you please try it?
what I meant was I tried the code snippet [1] locally and it seems to
work the same as the orig code but not any real testing e.g. CI, lets
see what the CI says (I am hopefull!!)
Noel
[1] actually I didn't test the foo = counter bit when I looked at it, I
added that now when you mentioned this part of the puzzle
+ python2
Python 2.7.14 (default, Oct 12 2017, 15:50:02) [GCC] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import itertools
>>> counter = itertools.count(1,1)
>>> print (next(counter))
1
>>> print (next(counter))
2
>>> foo = counter
>>> print (next(foo))
3
>>>
>>>
+ python3
Python 3.6.5 (default, Mar 31 2018, 19:45:04) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import itertools
>>> counter = itertools.count(1,1)
>>> print (next(counter))
1
>>> print (next(counter))
2
>>> foo = counter
>>> print (next(foo))
3
More information about the samba-technical
mailing list