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

fix: Faker seed should be random #223

Merged
merged 2 commits into from
Feb 10, 2025
Merged

fix: Faker seed should be random #223

merged 2 commits into from
Feb 10, 2025

Conversation

abraemer
Copy link
Contributor

Summary of changes

  • changes the seeding of Faker to guarantee a random seed for every run

Context and reason for change

The strength of Faker is the random generation of valid inputs. With a fixed seed this advantage is lost. For incomprehensible reasons, there was no randomization taking place. This PR fixes that be altering the setup slightly.

How the changes can be tested

Dump a few generated documents, e.g. by putting this snippet:

def test_generate(scancode_faker: ScanCodeFaker) -> None:
    scancode_data = scancode_faker.scancode_data()
    seed = int(datetime.now().timestamp())
    with open(f"generated_scancode-{seed}.json", "w") as out:
        out.write(scancode_data.model_dump_json(indent=4))

at the end of tests/input_formats/scancode/services/test_convert_to_opossum.py and running it a couple of times.
Before this change, this yields identical files. After this change, the file is different everytime.

* changes the seeding of Faker to guarantee a random seed for every run
* the inherently have no order, so using a set is more appropriate
* this also simplifies testing
Copy link
Contributor

@Hellgartner Hellgartner left a comment

Choose a reason for hiding this comment

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

LGTM

Will need a quick review after the final test fix ...

@Hellgartner Hellgartner merged commit ae29c46 into main Feb 10, 2025
10 checks passed
@Hellgartner Hellgartner deleted the fix-faker-seed branch February 10, 2025 10:33
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.

2 participants