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

test: removed unicode_test example from unit tests #11131

Merged
merged 13 commits into from
Oct 7, 2020

Conversation

kkucharc
Copy link
Contributor

@kkucharc kkucharc commented Oct 1, 2020

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

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

@kkucharc kkucharc changed the title [WIP] fix: removed unicode_test example from unit tests test: removed unicode_test example from unit tests [WIP] Oct 2, 2020
@kkucharc kkucharc added the test label Oct 2, 2020
@kkucharc kkucharc changed the title test: removed unicode_test example from unit tests [WIP] test: removed unicode_test example from unit tests Oct 2, 2020
@codecov-commenter
Copy link

codecov-commenter commented Oct 2, 2020

Codecov Report

Merging #11131 into master will decrease coverage by 5.03%.
The diff coverage is n/a.

Impacted file tree graph

@@            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     
Flag Coverage Δ
#cypress ?
#javascript ?
#python 60.75% <ø> (-0.66%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset/db_engines/hive.py 0.00% <0.00%> (-85.72%) ⬇️
superset/examples/unicode_test_data.py 22.00% <0.00%> (-78.00%) ⬇️
superset/db_engine_specs/hive.py 53.90% <0.00%> (-30.08%) ⬇️
superset/utils/decorators.py 50.76% <0.00%> (-4.24%) ⬇️
superset/examples/helpers.py 95.00% <0.00%> (-2.50%) ⬇️
superset/models/sql_lab.py 90.69% <0.00%> (-0.65%) ⬇️
superset/db_engine_specs/presto.py 81.42% <0.00%> (-0.50%) ⬇️
superset/utils/pandas_postprocessing.py 76.47% <0.00%> (-0.50%) ⬇️
superset/views/base_api.py 97.90% <0.00%> (-0.36%) ⬇️
superset/models/core.py 88.12% <0.00%> (-0.28%) ⬇️
... and 470 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d056e3d...55da74f. Read the comment docs.

Copy link
Member

@willbarrett willbarrett left a 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!

@willbarrett
Copy link
Member

@villebro @dpgaspar this is the first PR of a refactor to move away from the example data and to Pytest Fixtures. Please help validate the approach before we cross-apply this type of change to the rest of the suite.

tests/dashboard_utils.py Outdated Show resolved Hide resolved
return obj


def create_slice(title, viz_type, tbl, slices_dict: Dict[str, str]):
Copy link
Member

Choose a reason for hiding this comment

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

nit: missing return type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thanks 👍

tests/dashboard_utils.py Outdated Show resolved Hide resolved

db.session.commit()
position = "{}"
create_dashboard("unicode-test", "Unicode Test", position, None)
Copy link
Member

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)

Copy link
Contributor Author

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 Show resolved Hide resolved
tests/dashboard_utils.py Outdated Show resolved Hide resolved
Comment on lines 1135 to 1136
@pytest.fixture()
def load_unicode_dashboard(self):
Copy link
Member

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?

Copy link
Contributor Author

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 ?

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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 ! 💯

tests/strategy_tests.py Outdated Show resolved Hide resolved
Copy link
Member

@villebro villebro left a 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! 🚀



def create_table_for_dashboard(
df: DataFrame, tbl_name: str, database: Database, schema: Dict[str, Any]
Copy link
Member

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.

Suggested change
df: DataFrame, tbl_name: str, database: Database, schema: Dict[str, Any]
df: DataFrame, table_name: str, database: Database, schema: Dict[str, Any]

Copy link
Contributor Author

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.

tests/dashboard_utils.py Outdated Show resolved Hide resolved
tests/dashboard_utils.py Outdated Show resolved Hide resolved
tests/fixtures/unicode_dashboard.py Outdated Show resolved Hide resolved
Copy link
Member

@dpgaspar dpgaspar left a 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?

with app.app_context():
yield _create_unicode_dashboard(df, table_name, "Unicode Cloud", None)

_cleanup()
Copy link
Member

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

Copy link
Contributor Author

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.

@kkucharc
Copy link
Contributor Author

kkucharc commented Oct 6, 2020

@dpgaspar Thanks for review!
About moving file, I am not sure if putting this file in tests/dashboards/ would be good idea, since schedules_test.py and security_tests.py which also use it are in tests/ dir. Also actually api_tests.py which uses this fixture is in databases/ - not in dashboards/. But it still creates dashboards for those tests, so I don't have really strong opinion about it.

@kkucharc kkucharc requested a review from villebro October 6, 2020 17:29
@villebro
Copy link
Member

villebro commented Oct 7, 2020

@kkucharc do you prefer getting review comments now or wait until CI is passing?

@kkucharc
Copy link
Contributor Author

kkucharc commented Oct 7, 2020

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 :)

@kkucharc kkucharc requested a review from dpgaspar October 7, 2020 13:07
Copy link
Member

@villebro villebro left a 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!

tests/dashboard_utils.py Outdated Show resolved Hide resolved
Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
Copy link
Member

@dpgaspar dpgaspar left a comment

Choose a reason for hiding this comment

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

LGTM!

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()
Copy link
Member

@dpgaspar dpgaspar Oct 7, 2020

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-io
Copy link

codecov-io commented Oct 7, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@a071393). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #11131   +/-   ##
=========================================
  Coverage          ?   55.99%           
=========================================
  Files             ?      403           
  Lines             ?    13362           
  Branches          ?     3429           
=========================================
  Hits              ?     7482           
  Misses            ?     5696           
  Partials          ?      184           
Flag Coverage Δ
#cypress 55.99% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a071393...7c78f7a. Read the comment docs.

tests/dashboard_utils.py Outdated Show resolved Hide resolved
@villebro villebro merged commit 32e174d into apache:master Oct 7, 2020
auxten pushed a commit to auxten/incubator-superset that referenced this pull request Nov 20, 2020
* 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>
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.0.0 labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L 🚢 1.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants