Skip to content
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

Introduce formatted string generator #76

Closed
wants to merge 1 commit into from
Closed

Introduce formatted string generator #76

wants to merge 1 commit into from

Conversation

mfalesni
Copy link
Contributor

Introduce fauxfactory.generate() which takes a string with formatting similar to "".format() but instead of inserting strings, it randomizes the values based on what is located inside the braces.

@mfalesni
Copy link
Contributor Author

I wonder why does it hate line 807 in python 2.6. I think doing # NOQA or whatever works is OK here.

@Ichimonji10
Copy link
Contributor

Using # noqa isn't the right thing to do here, because flake8 is not complaining. The tool which is complaining is pylint. Old versions of pylint complain about the use of * and **, and it appears that the Python 2.6 environment uses an old version of pylint. (To be expected.) The appropriate comment is # pylint:disable=star-args.


Example of the formatter is:

``"test_vm_{alpha:12|.lower}"``
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An example of the formatter is::

    'test_vm_{alpha:12|.lower}'

See literal blocks.

Introduce `fauxfactory.generate()` which takes a string with formatting similar to `"".format()` but instead of inserting strings, it randomizes the values based on what is located inside the braces.
@mfalesni
Copy link
Contributor Author

@Ichimonji10 the pylint comment as you said triggered an error in all of the python versions. I have put the NOQA comment there to see if that one solves the issue. I also updated the example.

@mfalesni
Copy link
Contributor Author

Doesn't help either.

@elyezer
Copy link
Contributor

elyezer commented Jun 15, 2015

I think this is a good addition and a good start. The next step would be allowing one or more generators to be specified.

We need to take care of not reinventing some behaviours implemented by other libraries like rstr [1]

[1] https://pypi.python.org/pypi/rstr/2.1.3

@elyezer
Copy link
Contributor

elyezer commented Jun 15, 2015

Thinking better... I think that we can have the same behaviour without the need of any additional logic:

generate("test_vm_{alpha:12|.lower}")

# is the same as

'test_vm_{0}'.format(gen_alpha(12).lower())

With that said, by adding this kind of generator will not bring any real improvement because we can mix the python string formatting with the generators without the overhead of parsing the generator string.

Also the default string formatting allows generating not just one but many formats in the same string like:

'test_vm_{0}_{1}'.format(
    gen_alpha(5).lower(),
    gen_integer(3)
)

@Ichimonji10
Copy link
Contributor

The format() method already specifies a mini-language. See examples here. The mini-language uses the { and } characters to denote what should be interpolated. Having our own similar-but-incompatible formatting mini-language seems like a bad idea to me.

@omaciel
Copy link
Owner

omaciel commented Jun 15, 2015

@mfalesni After reviewing the PR and after considering the ultimate goal for it, I tend to agree with what @elyezer mentioned above. I feel that we'd be re-inventing the wheel and that perhaps this could be something that you can implement in your own code to handle your specific requirement?

@mfalesni
Copy link
Contributor Author

ok

@mfalesni mfalesni closed this Jun 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants