-
Notifications
You must be signed in to change notification settings - Fork 25
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
Auto-generate API documentation. Refactor code. #40
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
API Documentation | ||
================= | ||
|
||
This is a complete list of available methods, along with details about them. | ||
|
||
:mod:`fauxfactory` | ||
------------------ | ||
|
||
.. automodule:: fauxfactory | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ FauxFactory generates random data for your automated tests easily! | |
|
||
installation | ||
getting_started | ||
methods_available | ||
api | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Take note: I've dropped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,57 +22,45 @@ | |
|
||
|
||
def codify(data): | ||
""" | ||
Handles unicode compatibility with Python 3 | ||
"""Convert ``data`` to a unicode string if running Python 2. | ||
|
||
@type data: str | ||
@param data: String to return using unicode. | ||
:param str data: A string to be type cast. | ||
:return: ``data``, but as unicode. ``data`` is never modified: if a type | ||
cast is necessary, a copy of ``data`` is returned. | ||
|
||
@rtype: str | ||
@return: String in unicode format. | ||
""" | ||
|
||
try: | ||
result = unicode(data) | ||
except NameError: | ||
result = data | ||
|
||
return result | ||
if sys.version_info[0] is 2: | ||
return unicode(data) | ||
return data | ||
|
||
|
||
class FauxFactory(object): | ||
""" | ||
Generate random data for your tests. | ||
""" | ||
"""Generate random data for your tests.""" | ||
|
||
@classmethod | ||
def _is_positive_int(cls, length): | ||
""" | ||
Check that ``length`` argument is a valid integer, greater than zero. | ||
"""Check that ``length`` argument is an integer greater than zero. | ||
|
||
@type length: int | ||
@param length: The desired length of the string | ||
:param int length: The desired length of the string | ||
:raises: ``ValueError`` if ``length`` is not an ``int`` or is less than | ||
1. | ||
:returns: Nothing. | ||
:rtype: None | ||
|
||
@rtype: Exception | ||
@return: A ``ValueError`` exception | ||
""" | ||
|
||
# Validate length argument | ||
if not isinstance(length, int) or length <= 0: | ||
raise ValueError("%s is an invalid \'length\'." % length) | ||
raise ValueError("{} is an invalid 'length'.".format(length)) | ||
|
||
@classmethod | ||
def generate_string(cls, str_type, length): | ||
""" | ||
Create of a wide variety of string types, of arbitrary length. | ||
|
||
@type str_type: str | ||
@param str_type: The desired type of string to be generated. | ||
@type length: int | ||
@param length: Length for generated strng. | ||
"""A simple wrapper that calls other string generation methods. | ||
|
||
@rtype: int | ||
@return: A random string of the type and length specified. | ||
:param str str_type: The type of string which should be generated. | ||
:param int length: The length of the generated string. Must be 1 or | ||
greater. | ||
:raises: ``Exception`` if an invalid ``str_type`` is specified. | ||
:returns: A string. | ||
:rtype: str | ||
|
||
Valid values for ``str_type`` are as follows: | ||
|
||
|
@@ -83,27 +71,29 @@ def generate_string(cls, str_type, length): | |
* latin1 | ||
* numeric | ||
* utf8 | ||
""" | ||
|
||
# First lowercase the selected str type | ||
str_type = str_type.lower() | ||
|
||
if str_type == "alphanumeric": | ||
return cls.generate_alphanumeric(length) | ||
elif str_type == "alpha": | ||
return cls.generate_alpha(length) | ||
elif str_type == "latin1": | ||
return cls.generate_latin1(length) | ||
elif str_type == 'numeric': | ||
return cls.generate_numeric_string(length) | ||
elif str_type == "cjk": | ||
return cls.generate_cjk(length) | ||
elif str_type == "utf8": | ||
return cls.generate_utf8(length) | ||
elif str_type == "html": | ||
return cls.generate_html(length) | ||
""" | ||
str_types = ( | ||
'alpha', | ||
'alphanumeric', | ||
'cjk', | ||
'html', | ||
'latin1', | ||
'numeric', | ||
'utf8', | ||
) | ||
str_type_lower = str_type.lower() # do not modify user data | ||
if str_type_lower not in str_types: | ||
raise Exception( # FIXME: Raise a more specific exception. | ||
'{} is not a supported string type. Valid string types are {}.' | ||
''.format(str_type_lower, str_types) | ||
) | ||
if str_type_lower == 'numeric': | ||
method = cls.generate_numeric_string | ||
else: | ||
raise Exception("%s is not a supported string type." % str_type) | ||
method = getattr(cls, 'generate_{}'.format(str_type_lower)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Niice |
||
return method(length) | ||
|
||
|
||
@classmethod | ||
def generate_alpha(cls, length=5): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already stated in introduction.