So I'd rather go with these methods inlined in
'make_from_configuration'. This way the reader can focus on the still short
enough 'make_from_configuration'.
An additional trap in your implementation is that the two methods are not in
the order they are used (so, as a reader, if I don't pay attention enough I
won't notice and read the wrong method when reading 'make_for_test').
'_make_random_test_user_from_configuration' and
'_make_test_user_from_configuration' being this long (note that I can't cite
them both on a 80 chars long line), it's hard to spot the differing
'random', that's, for me, an example of why names too long hurt readability
instead of helping it. Rmeebmer that popele are good at recgniozing words
based on the first and last letetr even if the letters inside the words are
suhffled (you managed to read this sentence without too much trouble aren't
you ? ;).
I.e.:
....
wth, I cannot branch lp:osqa-sst-helpers ? What is this project about ? 8-/
(that was rhetorical, the development focus needs to be set in lp).
Some naming remarks:
50 + def make_for_ test(klass, new_user=False):
Well, we know it's for test since the whole class is for tests.
53 + test_user = klass._ make_random_ test_user_ from_configurat ion()
55 + test_user = klass._ make_test_ user_from_ configuration( )
Since all use cases are from configuration, I'd rather name this method 'make_from_ configuration' .
58 + @classmethod test_user_ from_configurat ion(klass) : EMAIL_ADDRESS_ PATTERN % random_user_uuid SSO_TEST_ ACCOUNT_ PASSWORD user_from_ configuration( klass): SSO_TEST_ ACCOUNT_ FULL_NAME SSO_TEST_ ACCOUNT_ EMAIL SSO_TEST_ ACCOUNT_ PASSWORD
59 + def _make_random_
60 + random_user_uuid = str(uuid.uuid1())
61 + full_name = 'Test user ' + random_user_uuid
62 + email_address = settings.
63 + password = settings.
64 + return klass(full_name, email_address, password)
65 +
66 + @classmethod
67 + def _make_test_
68 + full_name = settings.
69 + email_address = settings.
70 + password = settings.
71 + return klass(full_name, email_address, password)
I think having these methods hurt readability and make for more duplication:
49 + @classmethod
58 + @classmethod
66 + @classmethod
63 + password = settings. SSO_TEST_ ACCOUNT_ PASSWORD
64 + return klass(full_name, email_address, password)
70 + password = settings. SSO_TEST_ ACCOUNT_ PASSWORD
71 + return klass(full_name, email_address, password)
So I'd rather go with these methods inlined in configuration' . This way the reader can focus on the still short configuration' .
'make_from_
enough 'make_from_
An additional trap in your implementation is that the two methods are not in
the order they are used (so, as a reader, if I don't pay attention enough I
won't notice and read the wrong method when reading 'make_for_test').
'_make_ random_ test_user_ from_configurat ion' and test_user_ from_configurat ion' being this long (note that I can't cite
'_make_
them both on a 80 chars long line), it's hard to spot the differing
'random', that's, for me, an example of why names too long hurt readability
instead of helping it. Rmeebmer that popele are good at recgniozing words
based on the first and last letetr even if the letters inside the words are
suhffled (you managed to read this sentence without too much trouble aren't
you ? ;).
I.e.:
....
wth, I cannot branch lp:osqa-sst-helpers ? What is this project about ? 8-/
(that was rhetorical, the development focus needs to be set in lp).
anyway:
=== modified file 'sso_sst_ helpers/ data.py' helpers/ data.py 2012-10-10 21:07:11 +0000 helpers/ data.py 2012-10-11 07:47:48 +0000
--- sso_sst_
+++ sso_sst_
@@ -30,25 +30,13 @@
return '%s(%r)' % (self.__class__, self.__dict__)
@classmethod test(klass, new_user=False): configuration( klass, new_user=False): make_random_ test_user_ from_configurat ion() SSO_TEST_ ACCOUNT_ FULL_NAME SSO_TEST_ ACCOUNT_ EMAIL make_test_ user_from_ configuration( ) test_user_ from_configurat ion(klass) : EMAIL_ADDRESS_ PATTERN % random_user_uuid SSO_TEST_ ACCOUNT_ PASSWORD user_from_ configuration( klass): SSO_TEST_ ACCOUNT_ FULL_NAME SSO_TEST_ ACCOUNT_ EMAIL SSO_TEST_ ACCOUNT_ PASSWORD EMAIL_ADDRESS_ PATTERN % random_user_uuid
- def make_for_
+ def make_from_
test_user = None
if new_user:
- test_user = klass._
+ full_name = settings.
+ email_address = settings.
else:
- test_user = klass._
- return test_user
-
- @classmethod
- def _make_random_
- random_user_uuid = str(uuid.uuid1())
- full_name = 'Test user ' + random_user_uuid
- email_address = settings.
- password = settings.
- return klass(full_name, email_address, password)
-
- @classmethod
- def _make_test_
- full_name = settings.
- email_address = settings.
- password = settings.
+ random_user_uuid = str(uuid.uuid1())
+ full_name = 'Test user ' + random_user_uuid
+ email_address = settings.
return klass(full_name, email_address, password)
bzr diffstat for the above says:
sso_sst_ helpers/ data.py | 24 ++++++- ------- ------- ---
1 file changed, 6 insertions(+), 18 deletions(-)
The resulting method is 11 lines long instead of 21 for the 3 methods, less
to read, more readable.