Skip to content

Add Color locale tests; migrate color lists from commerce.color to color.name#1715

Merged
asolntsev merged 4 commits intodatafaker-net:mainfrom
vicky-iv:color-tests
Nov 6, 2025
Merged

Add Color locale tests; migrate color lists from commerce.color to color.name#1715
asolntsev merged 4 commits intodatafaker-net:mainfrom
vicky-iv:color-tests

Conversation

@vicky-iv
Copy link
Copy Markdown
Contributor

@vicky-iv vicky-iv commented Nov 3, 2025

I noticed an inconsistency in how color values are stored across different languages.
In some files, color was part of the сommerce entity, but I couldn’t find any usages of commerce.color in the code, and the Commerce class doesn’t have a color() method.

Therefore, I propose to normalize the color data and always store color as a separate entity in the color.name format.

PR description

  • Introduces ColorLocaleTest to verify Color.name() localization across many locales.
  • Extends BaseFakerLocaleTest with additional BaseFaker instances
  • Moves color data from commerce.color to color.name for several locales to normalize where the Color provider reads from and to remove duplication.
  • Locales updated in resources: be.yml, by.yml, da-DK.yml, ru.yml, sv.yml, uk.yml (add color.name blocks; remove commerce.color where applicable), and uz.yml (remove commerce.color as duplicate).

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Nov 3, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.32%. Comparing base (e780354) to head (fd6f819).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1715      +/-   ##
============================================
- Coverage     92.41%   92.32%   -0.09%     
+ Complexity     3438     3434       -4     
============================================
  Files           337      337              
  Lines          6779     6779              
  Branches        670      670              
============================================
- Hits           6265     6259       -6     
- Misses          352      354       +2     
- Partials        162      166       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@asolntsev asolntsev added this to the 2.6.0 milestone Nov 4, 2025
@asolntsev asolntsev added enhancement New feature or request refactoring labels Nov 4, 2025
Copy link
Copy Markdown
Collaborator

@asolntsev asolntsev left a comment

Choose a reason for hiding this comment

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

Nice job, thank you @vicky-iv !

P.S. I have been thinking about all these localeProviderListTest (like ColorLocaleTest in this case). What exactly do they test? What type of error can they catch?
They seems useless for me...
At least,

  • instead of listing all locales manually, we can generate the locales list automatically.
  • instead of listing alll yml keys like "color.name" manunally, we could generate this list automatically (e.g. using annotations).

@vicky-iv
Copy link
Copy Markdown
Contributor Author

vicky-iv commented Nov 4, 2025

@asolntsev Thanks for your comment!
These tests use the method net.datafaker.providers.base.AbstractProviderListTest#testProviderList, which is used across all provider tests. In #1704, I added the ability to use the same method in the locale tests.

instead of listing all locales manually, we can generate the locales list automatically.

Some locales don't have a list of colors, so I thought it would make sense to add locales manually.

instead of listing all yml keys like "color.name" manunally, we could generate this list automatically (e.g. using annotations).

Automatically generating the list sounds like a good idea, but it won’t work in all cases. In some tests we might need to cover more complex entities with multiple parameters. A good example is net.datafaker.providers.base.VehicleLocaleTest#localeProviderListTest

@snuyanzin
Copy link
Copy Markdown
Collaborator

@vicky-iv

Automatically generating the list sounds like a good idea, but it won’t work in all cases. In some tests we might need to cover more complex entities with multiple parameters. A good example is

I added a PR to your branch generalizing this
WDYT about this?
vicky-iv#1

@vicky-iv vicky-iv requested a review from asolntsev November 5, 2025 17:48
@vicky-iv
Copy link
Copy Markdown
Contributor Author

vicky-iv commented Nov 5, 2025

@asolntsev I slightly improved ColorLocaleTest, it still requires manually adding locales because not every locale includes color, but the implementation is no longer bulky.

Thanks @snuyanzin for the idea!

Copy link
Copy Markdown
Collaborator

@asolntsev asolntsev left a comment

Choose a reason for hiding this comment

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

All good, thank you for the PR.

My doubt is more general. I don't understand what exactly does this test verify?
What type of error can it potentially catch? For me, it seems a useless test.
Not only this one, but all the previous similar tests.

    @Override
    protected Stream<Arguments> localeProviderListTest() {
        return fakers.stream()
            .map(faker -> arguments(TestSpec.of(() -> faker.color().name(), "color.name"), faker));
    }

@asolntsev asolntsev merged commit 4aa5c2e into datafaker-net:main Nov 6, 2025
13 checks passed
@kingthorin
Copy link
Copy Markdown
Collaborator

We’ve been through that discussion before.

@asolntsev
Copy link
Copy Markdown
Collaborator

... And what was the answer?

@kingthorin
Copy link
Copy Markdown
Collaborator

It was a few things:

  • It reduces the chances of someone making a copy/paste mistake and having the wrong key resolved for a given method
  • It replaced previous regex tests that were simply "this string has content"
  • It is meant to be extended further so that more and more content is covered with decent regex patterns (which the TestSpec supports)

If you need more you'll have to go looking. I don't want to rehash it.

@asolntsev
Copy link
Copy Markdown
Collaborator

@kingthorin Sorry, I should not waste your time by asking this.
That's right, we already discussed it. Sorry.

I will try to prepare PR if I get some idea how to improve these tests.

@kingthorin
Copy link
Copy Markdown
Collaborator

No worries, sorry if my response seemed negative or harsh; things weren't going well yesterday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants