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

Incorrect type returned from falsey 0.0 #36

Merged
merged 1 commit into from
Oct 4, 2022
Merged

Conversation

AkhilGNair
Copy link

@AkhilGNair AkhilGNair commented Aug 4, 2022

Hi!

Thank you for the package :) it's really useful.

I think your test_nullable_types_gen test fails if run with sufficient random data:

====================== test session starts ======================
platform linux -- Python 3.10.5, pytest-7.1.2, pluggy-1.0.0
rootdir: ...
plugins: Faker-13.15.1
collected 63 items                                              

src/tests/test_cli.py .                                   [  1%]
src/tests/test_default_fake.py .....................      [ 34%]
src/tests/test_model_gen.py ............                  [ 53%]
src/tests/test_nullable_types_gen.py .F.......            [ 68%]
src/tests/test_parser.py ...............                  [ 92%]
src/tests/test_utils.py .....                             [100%]

=========================== FAILURES ============================
_______________________ test_int_null_gen _______________________

TestData = PosixPath('...')

    def test_int_null_gen(TestData):
        with open(TestData / f"type-list-null.json", "r") as file:
            schema = json.load(file)
        p = JSF(schema["int"])
    
        actual = [p.generate() for _ in range(100000)]
>       assert all(type(each) in [type(None), int] for each in actual)
E       assert False
E        +  where False = all(<generator object test_int_null_gen.<locals>.<genexpr> at 0x7f60271a3990>)

src/tests/test_nullable_types_gen.py:22: AssertionError
==================== short test summary info ====================
FAILED src/tests/test_nullable_types_gen.py::test_int_null_gen
================= 1 failed, 62 passed in 3.05s ==================

For example, here I have changed the number of generated values from 100 to 100,000 to produce an error.

In this case in particular, it is because occasionally the float 0.0 is generated, which is falsey and so gets passed through as a float. Making the check explicitly for is not None fixes this.

Unfortunately, I can't come up with a better way to permanently fix the test...
If you can suggest anything, I am happy to add.

Thanks!
Akhil

@AkhilGNair AkhilGNair changed the title Fix error from falsey 0 Fix incorrect type from falsey 0 Aug 4, 2022
@AkhilGNair AkhilGNair changed the title Fix incorrect type from falsey 0 Incorrect type returned from falsey 0.0 Aug 4, 2022
@ghandic ghandic merged commit 18eb2e6 into ghandic:main Oct 4, 2022
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

2 participants