-
Notifications
You must be signed in to change notification settings - Fork 13.9k
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
test: removed unicode_test example from unit tests #11131
Conversation
Codecov Report
@@ Coverage Diff @@
## master #11131 +/- ##
==========================================
- Coverage 65.79% 60.75% -5.04%
==========================================
Files 816 391 -425
Lines 38422 24483 -13939
Branches 3621 0 -3621
==========================================
- Hits 25280 14875 -10405
+ Misses 13034 9608 -3426
+ Partials 108 0 -108
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
Kasha, I think this is a solid approach. Thank you for taking this on, and please continue!
tests/dashboard_utils.py
Outdated
return obj | ||
|
||
|
||
def create_slice(title, viz_type, tbl, slices_dict: Dict[str, str]): |
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.
nit: missing return type
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.
Fixed, thanks 👍
tests/databases/api_tests.py
Outdated
|
||
db.session.commit() | ||
position = "{}" | ||
create_dashboard("unicode-test", "Unicode Test", position, None) |
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.
What's being done on other pytest fixtures is to yield create_dashboard("unicode-test", "Unicode Test", position, None)
and then clean everything up (on this case delete the dashboard and then delete the table for dashboard)
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.
Thanks for the hint. I changed it this way. Thanks to that I also removed deleting dashboard from conftest.py
tests/security_tests.py
Outdated
@pytest.fixture() | ||
def load_unicode_dashboard(self): |
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.
Should we put this in fixtures.py
so we don't have to repeat this logic wherever we use the unicode dashboard?
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.
Sounds good. I just wanted to clarify if you mean moving to fixtures/
directory? My only concern is about some fixtures that create slices for dashboards (or some other setup). I wondered if wouldn't be better to have just some common parts to combine those dashboard creation parts into particular fixtures (as there is this new file dashboard_utils
. Or maybe having basic fixture which will be extended or decorated in more complex cases? WDYT @villebro ?
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.
@kkucharc you are right, I meant the fixtures/
directory! Perhaps we could create something like fixtures/unicode.py
that would for now just include def load_unicode_dashboard()
. Down the road I actually think it would be great to try to decouple datasets, charts and dashboards from each other, as may backend tests don't necessarily need the full suite of charts and dashboards, but are ok with just the dataset. Having said that, let's take gradual steps here, so as to not choke on trying to make this perfect on first iteration.
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.
That makes sens. I refactored this part. To be honest, I'm proud of this :) - I hope this will be good step on first iteration of this refactor. WDYT?
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.
Yeah, I really like this refactor! Hi-5 @kkucharc ! 💯
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.
Second pass, mostly nits. I'm really loving this, super nice! 🚀
tests/dashboard_utils.py
Outdated
|
||
|
||
def create_table_for_dashboard( | ||
df: DataFrame, tbl_name: str, database: Database, schema: Dict[str, Any] |
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.
nit: I personally find table_name
more pythonic.
df: DataFrame, tbl_name: str, database: Database, schema: Dict[str, Any] | |
df: DataFrame, table_name: str, database: Database, schema: Dict[str, Any] |
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.
I am also for more descriptive names instead of shortcuts. I changed it in both of my files.
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.
I like the pattern of having idempotent tests, where the state of the DB is kept between tests.
This is looking good!
What do you think about changing the file location for tests/fixtures/unicode_dashboard.py
to tests/dashboards/fixtures.py
or tests/dashboards/fixtures/unicode.py
for example?
tests/fixtures/unicode_dashboard.py
Outdated
with app.app_context(): | ||
yield _create_unicode_dashboard(df, table_name, "Unicode Cloud", None) | ||
|
||
_cleanup() |
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.
the _cleanup()
is not actually cleaning up. The dashboard is still there. My idea is to make all test idempotent so we can run them multiple times and would help to clean weird behaviours (for example changing a test run order would make the test fail). So I think we should delete the dashboard also
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.
Sure, you are right. I also added removing slice because apparently it doesn't cleanup after deleting particular dashboard record.
@dpgaspar Thanks for review! |
@kkucharc do you prefer getting review comments now or wait until CI is passing? |
…veral methods. Added param types and return types.
da61088
to
8f5ec97
Compare
I guess it was worth waiting for CI, because apparently cleanup had impact on charts tests. I also rebased because of conflicts. @villebro I think it's ready now :) |
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.
One small comment, but I consider this ready to go. LGTM and great work @kkucharc!
Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
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.
LGTM!
tests/fixtures/unicode_dashboard.py
Outdated
engine.execute("DROP TABLE IF EXISTS unicode_test") | ||
db.session.delete(dash) | ||
if slice_name: | ||
slice = db.session.query(Slice).filter_by(slice_name=slice_name).first() |
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.
nit: slice = db.session.query(Slice).filter_by(slice_name=slice_name).one_or_none()
Codecov Report
@@ Coverage Diff @@
## master #11131 +/- ##
=========================================
Coverage ? 55.99%
=========================================
Files ? 403
Lines ? 13362
Branches ? 3429
=========================================
Hits ? 7482
Misses ? 5696
Partials ? 184
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
…rst element with one_or_none
* Removed depemdency to unicode example in tests config. * Added common methods for creating dashboards for tests. * Added fixtures to all tests which were using unicode example. * Added cleanup for unicode_test table * Removed unnecessary fixture parts of unicode dashboard tests * Parametrized creating slice for tests * Moved fixtures for unicode test to separate file and refactored to several methods. Added param types and return types. * Cleandup after fix * Changed variable names to more readable * Added cleanup for dashboards and slices * Applied unicode fixture to charts api tests * Update schema variable to dtype in dashboard utils Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com> * Changed variable schema to dtype in dashboards. Replaced accessing first element with one_or_none Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
SUMMARY
To improve development of unit/integration tests development, here is suggestion of removing
unicode_test
project examples loaded in tests setup and replacing it with fixtures that creates dashboard with sample of unicode data.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TEST PLAN
ADDITIONAL INFORMATION