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

Separate Pandas and SQL test suite #354

Merged
merged 1 commit into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ jobs:
- name: Test with Pytest and Code Coverage Report
run: |
pytest --cov-report term --cov=lux tests/
pytest --cov-report term --cov=lux tests_sql/
bash <(curl -s https://codecov.io/bash)
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ init:
test:
black --check .
python -m pytest tests/

test_all:
black --check .
python -m pytest tests/
python -m pytest tests_sql/
.PHONY: init test
263 changes: 0 additions & 263 deletions tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,6 @@ def test_underspecified_no_vis(global_var, test_recs):
assert len(df.current_vis) == 0
df.clear_intent()

# test for sql executor
connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
lux.config.set_SQL_connection(connection)
sql_df = lux.LuxSQLTable(table_name="cars")

test_recs(sql_df, no_vis_actions)
assert len(sql_df.current_vis) == 0

# test only one filter context case.
sql_df.set_intent([lux.Clause(attribute="origin", filter_op="=", value="USA")])
test_recs(sql_df, no_vis_actions)
assert len(sql_df.current_vis) == 0


def test_underspecified_single_vis(global_var, test_recs):
lux.config.set_executor_type("Pandas")
Expand All @@ -60,18 +47,6 @@ def test_underspecified_single_vis(global_var, test_recs):
assert attr.data_type == "quantitative"
df.clear_intent()

connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
lux.config.set_SQL_connection(connection)
sql_df = lux.LuxSQLTable(table_name="cars")
sql_df.set_intent([lux.Clause(attribute="milespergal"), lux.Clause(attribute="weight")])
test_recs(sql_df, one_vis_actions)
assert len(sql_df.current_vis) == 1
assert sql_df.current_vis[0].mark == "scatter"
for attr in sql_df.current_vis[0]._inferred_intent:
assert attr.data_model == "measure"
for attr in sql_df.current_vis[0]._inferred_intent:
assert attr.data_type == "quantitative"


# def test_underspecified_vis_collection(test_recs):
# multiple_vis_actions = ["Current viss"]
Expand Down Expand Up @@ -115,15 +90,6 @@ def test_set_intent_as_vis(global_var, test_recs):
df._ipython_display_()
test_recs(df, ["Enhance", "Filter", "Generalize"])

connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
lux.config.set_SQL_connection(connection)
sql_df = lux.LuxSQLTable(table_name="cars")
sql_df._repr_html_()
vis = sql_df.recommendation["Correlation"][0]
sql_df.intent = vis
sql_df._repr_html_()
test_recs(sql_df, ["Enhance", "Filter", "Generalize"])


@pytest.fixture
def test_recs():
Expand All @@ -150,18 +116,6 @@ def test_parse(global_var):
vlst = VisList([lux.Clause("Origin=?"), lux.Clause("MilesPerGal")], df)
assert len(vlst) == 3

connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
lux.config.set_SQL_connection(connection)
sql_df = lux.LuxSQLTable(table_name="cars")
vlst = VisList([lux.Clause("origin=?"), lux.Clause(attribute="milespergal")], sql_df)
assert len(vlst) == 3

connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
lux.config.set_SQL_connection(connection)
sql_df = lux.LuxSQLTable(table_name="cars")
vlst = VisList([lux.Clause("origin=?"), lux.Clause("milespergal")], sql_df)
assert len(vlst) == 3


def test_underspecified_vis_collection_zval(global_var):
lux.config.set_executor_type("Pandas")
Expand All @@ -181,18 +135,6 @@ def test_underspecified_vis_collection_zval(global_var):
# vlst = VisList([lux.Clause(attribute = ["Origin","Cylinders"], filter_op="=",value="?"),lux.Clause(attribute = ["Horsepower"]),lux.Clause(attribute = "Weight")],df)
# assert len(vlst) == 8

connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
lux.config.set_SQL_connection(connection)
sql_df = lux.LuxSQLTable(table_name="cars")
vlst = VisList(
[
lux.Clause(attribute="origin", filter_op="=", value="?"),
lux.Clause(attribute="milespergal"),
],
sql_df,
)
assert len(vlst) == 3


def test_sort_bar(global_var):
from lux.processor.Compiler import Compiler
Expand Down Expand Up @@ -221,32 +163,6 @@ def test_sort_bar(global_var):
assert vis.mark == "bar"
assert vis._inferred_intent[1].sort == "ascending"

connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
lux.config.set_SQL_connection(connection)
sql_df = lux.LuxSQLTable(table_name="cars")
vis = Vis(
[
lux.Clause(attribute="acceleration", data_model="measure", data_type="quantitative"),
lux.Clause(attribute="origin", data_model="dimension", data_type="nominal"),
],
sql_df,
)
assert vis.mark == "bar"
assert vis._inferred_intent[1].sort == ""

connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
lux.config.set_SQL_connection(connection)
sql_df = lux.LuxSQLTable(table_name="cars")
vis = Vis(
[
lux.Clause(attribute="acceleration", data_model="measure", data_type="quantitative"),
lux.Clause(attribute="name", data_model="dimension", data_type="nominal"),
],
sql_df,
)
assert vis.mark == "bar"
assert vis._inferred_intent[1].sort == "ascending"


def test_specified_vis_collection(global_var):
lux.config.set_executor_type("Pandas")
Expand Down Expand Up @@ -335,16 +251,6 @@ def test_autoencoding_scatter(global_var):
)
df.clear_intent()

connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
lux.config.set_SQL_connection(connection)
sql_df = lux.LuxSQLTable(table_name="cars")
visList = VisList(
[lux.Clause(attribute="?"), lux.Clause(attribute="milespergal", channel="x")],
sql_df,
)
for vis in visList:
check_attribute_on_channel(vis, "milespergal", "x")


def test_autoencoding_scatter():
lux.config.set_executor_type("Pandas")
Expand Down Expand Up @@ -388,45 +294,6 @@ def test_autoencoding_scatter():
]
)

# test for sql executor
connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
lux.config.set_SQL_connection(connection)
sql_df = lux.LuxSQLTable(table_name="cars")
vis = Vis([lux.Clause(attribute="milespergal"), lux.Clause(attribute="weight")], sql_df)
check_attribute_on_channel(vis, "milespergal", "x")
check_attribute_on_channel(vis, "weight", "y")

# Partial channel specified
vis = Vis(
[
lux.Clause(attribute="milespergal", channel="y"),
lux.Clause(attribute="weight"),
],
sql_df,
)
check_attribute_on_channel(vis, "milespergal", "y")
check_attribute_on_channel(vis, "weight", "x")

# Full channel specified
vis = Vis(
[
lux.Clause(attribute="milespergal", channel="y"),
lux.Clause(attribute="weight", channel="x"),
],
sql_df,
)
check_attribute_on_channel(vis, "milespergal", "y")
check_attribute_on_channel(vis, "weight", "x")
# Duplicate channel specified
with pytest.raises(ValueError):
# Should throw error because there should not be columns with the same channel specified
sql_df.set_intent(
[
lux.Clause(attribute="milespergal", channel="x"),
lux.Clause(attribute="weight", channel="x"),
]
)


def test_autoencoding_histogram(global_var):
lux.config.set_executor_type("Pandas")
Expand All @@ -441,18 +308,6 @@ def test_autoencoding_histogram(global_var):
assert vis.get_attr_by_channel("x")[0].attribute == "MilesPerGal"
assert vis.get_attr_by_channel("y")[0].attribute == "Record"

# No channel specified
# test for sql executor
connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
lux.config.set_SQL_connection(connection)
sql_df = lux.LuxSQLTable(table_name="cars")
vis = Vis([lux.Clause(attribute="milespergal", channel="y")], sql_df)
check_attribute_on_channel(vis, "milespergal", "y")

vis = Vis([lux.Clause(attribute="milespergal", channel="x")], sql_df)
assert vis.get_attr_by_channel("x")[0].attribute == "milespergal"
assert vis.get_attr_by_channel("y")[0].attribute == "Record"


def test_autoencoding_line_chart(global_var):
lux.config.set_executor_type("Pandas")
Expand Down Expand Up @@ -495,45 +350,6 @@ def test_autoencoding_line_chart(global_var):
)
df.clear_intent()

# test for sql executor
connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
lux.config.set_SQL_connection(connection)
sql_df = lux.LuxSQLTable(table_name="cars")
vis = Vis([lux.Clause(attribute="year"), lux.Clause(attribute="acceleration")], sql_df)
check_attribute_on_channel(vis, "year", "x")
check_attribute_on_channel(vis, "acceleration", "y")

# Partial channel specified
vis = Vis(
[
lux.Clause(attribute="year", channel="y"),
lux.Clause(attribute="acceleration"),
],
sql_df,
)
check_attribute_on_channel(vis, "year", "y")
check_attribute_on_channel(vis, "acceleration", "x")

# Full channel specified
vis = Vis(
[
lux.Clause(attribute="year", channel="y"),
lux.Clause(attribute="acceleration", channel="x"),
],
sql_df,
)
check_attribute_on_channel(vis, "year", "y")
check_attribute_on_channel(vis, "acceleration", "x")

with pytest.raises(ValueError):
# Should throw error because there should not be columns with the same channel specified
sql_df.set_intent(
[
lux.Clause(attribute="year", channel="x"),
lux.Clause(attribute="acceleration", channel="x"),
]
)


def test_autoencoding_color_line_chart(global_var):
lux.config.set_executor_type("Pandas")
Expand All @@ -550,20 +366,6 @@ def test_autoencoding_color_line_chart(global_var):
check_attribute_on_channel(vis, "Acceleration", "y")
check_attribute_on_channel(vis, "Origin", "color")

# test for sql executor
connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
lux.config.set_SQL_connection(connection)
sql_df = lux.LuxSQLTable(table_name="cars")
intent = [
lux.Clause(attribute="year"),
lux.Clause(attribute="acceleration"),
lux.Clause(attribute="origin"),
]
vis = Vis(intent, sql_df)
check_attribute_on_channel(vis, "year", "x")
check_attribute_on_channel(vis, "acceleration", "y")
check_attribute_on_channel(vis, "origin", "color")


def test_autoencoding_color_scatter_chart(global_var):
lux.config.set_executor_type("Pandas")
Expand All @@ -590,30 +392,6 @@ def test_autoencoding_color_scatter_chart(global_var):
)
check_attribute_on_channel(vis, "Acceleration", "color")

# test for sql executor
connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
lux.config.set_SQL_connection(connection)
sql_df = lux.LuxSQLTable(table_name="cars")
vis = Vis(
[
lux.Clause(attribute="horsepower"),
lux.Clause(attribute="acceleration"),
lux.Clause(attribute="origin"),
],
sql_df,
)
check_attribute_on_channel(vis, "origin", "color")

vis = Vis(
[
lux.Clause(attribute="horsepower"),
lux.Clause(attribute="acceleration", channel="color"),
lux.Clause(attribute="origin"),
],
sql_df,
)
check_attribute_on_channel(vis, "acceleration", "color")


def test_populate_options(global_var):
lux.config.set_executor_type("Pandas")
Expand Down Expand Up @@ -644,33 +422,6 @@ def test_populate_options(global_var):
)
df.clear_intent()

# test for sql executor
connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
lux.config.set_SQL_connection(connection)
sql_df = lux.LuxSQLTable(table_name="cars")
sql_df.set_intent([lux.Clause(attribute="?"), lux.Clause(attribute="milespergal")])
col_set = set()
for specOptions in Compiler.populate_wildcard_options(sql_df._intent, sql_df)["attributes"]:
for clause in specOptions:
col_set.add(clause.attribute)
assert list_equal(list(col_set), list(sql_df.columns))

sql_df.set_intent(
[
lux.Clause(attribute="?", data_model="measure"),
lux.Clause(attribute="milespergal"),
]
)
sql_df._repr_html_()
col_set = set()
for specOptions in Compiler.populate_wildcard_options(sql_df._intent, sql_df)["attributes"]:
for clause in specOptions:
col_set.add(clause.attribute)
assert list_equal(
list(col_set),
["acceleration", "weight", "horsepower", "milespergal", "displacement"],
)


def test_remove_all_invalid(global_var):
lux.config.set_executor_type("Pandas")
Expand All @@ -687,20 +438,6 @@ def test_remove_all_invalid(global_var):
assert len(df.current_vis) == 0
df.clear_intent()

# test for sql executor
connection = psycopg2.connect("host=localhost dbname=postgres user=postgres password=lux")
lux.config.set_SQL_connection(connection)
sql_df = lux.LuxSQLTable(table_name="cars")
# with pytest.warns(UserWarning,match="duplicate attribute specified in the intent"):
sql_df.set_intent(
[
lux.Clause(attribute="origin", filter_op="=", value="USA"),
lux.Clause(attribute="origin"),
]
)
sql_df._repr_html_()
assert len(sql_df.current_vis) == 0


def list_equal(l1, l2):
l1.sort()
Expand Down
Loading