New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow zero-length strings #22
Comments
My logic for not allowing zero-length strings is because if that is the case then you could just pass As far as refactoring the code that performs the validation, I agree and will do that soon-ish (unless you beat me to the punch and send me a PR) :) |
If you refactor out that validation logic, your test suite can be trimmed down significantly. |
Cool, will do that today. |
If you look at pull request 20, you'll see I only have three unit tests for In my opinion. ;) |
@Ichimonji10 created PR #23 and would love your feedback before merging it. Btw, interestingly enough, when I run the test suite locally (python 2.7) I keep getting the following errors (though Travis seems to be happy): ======================================================================
ERROR: @Test: Create a unicode string.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/omaciel/hacking/fauxfactory/tests/test_strings.py", line 351, in test_generate_utf8_1
result = self.factory.generate_string('utf8', 5)
File "/Users/omaciel/hacking/fauxfactory/fauxfactory/__init__.py", line 85, in generate_string
return cls.generate_utf8(length)
File "/Users/omaciel/hacking/fauxfactory/fauxfactory/__init__.py", line 636, in generate_utf8
output = u''.join(unichr(codepoint) for codepoint in codepoints)
File "/Users/omaciel/hacking/fauxfactory/fauxfactory/__init__.py", line 636, in <genexpr>
output = u''.join(unichr(codepoint) for codepoint in codepoints)
ValueError: unichr() arg not in range(0x10000) (narrow Python build)
======================================================================
ERROR: @Test: Create a unicode string and specify a length.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/omaciel/hacking/fauxfactory/tests/test_strings.py", line 366, in test_generate_utf8_2
len(self.factory.generate_string('utf8', length)),
File "/Users/omaciel/hacking/fauxfactory/fauxfactory/__init__.py", line 85, in generate_string
return cls.generate_utf8(length)
File "/Users/omaciel/hacking/fauxfactory/fauxfactory/__init__.py", line 636, in generate_utf8
output = u''.join(unichr(codepoint) for codepoint in codepoints)
File "/Users/omaciel/hacking/fauxfactory/fauxfactory/__init__.py", line 636, in <genexpr>
output = u''.join(unichr(codepoint) for codepoint in codepoints)
ValueError: unichr() arg not in range(0x10000) (narrow Python build)
----------------------------------------------------------------------
Ran 150 tests in 0.849s
FAILED (errors=2) |
Could be my version of python 2.7 after all: http://wordaligned.org/articles/narrow-python Running on recently installed python 3.4 shows no issues: python3 -m unittest discover tests
......................................................................................................................................................
----------------------------------------------------------------------
Ran 150 tests in 0.310s
OK |
Good article. You can discover whether your Python 2 executable is compiled with narrow or wide unicode support by executing the following:
On my dev machine, a value of 4 is returned, which would explain why I am sucessfully able to execute the test suite without encountering encoding issues. When I execute the same instructions under Python 3.4.0, I get a All that said, the question arises: should the
That said, we cannot anticipate all use cases for FauxFactory. Some users may be interested in only providing "narrow" unicode support. If this is the case, then a |
To restate my argument from above, in fewer words: Incomplete support for UTF-8 is something users should be aware of. |
@Ichimonji10 ping. Is this still relevant? |
I've not needed zero-length strings for the past several months, so no. |
Methods like
generate_alphanumeric
andgenerate_alpha
allow the user to choose how long the resultant string should be. Each of those string generation methods checkslength
to ensure that the value is an integer and is not too short. There are two problems here:'length
of zero is not allowed. That doesn't make sense. A user should be able to generate a zero-length string if they so desire.The text was updated successfully, but these errors were encountered: