Skip to content

Commit

Permalink
move tests and sphinxext outside folder application code (#2792)
Browse files Browse the repository at this point in the history
* move tests to test folder

* define path sphinxext extensions

* rename examples folder and init function

* exclude examples_arguments_syntax dir for black

* fix linting

* exclude example files for flake and black

* apply pytest to tests folder

* update makefile to test tests folder

* add missing pytest-cov to requirements_dev file

* add missing .py extension to example file
  • Loading branch information
mattijn authored Jan 2, 2023
1 parent 6638ca5 commit 0d82108
Show file tree
Hide file tree
Showing 230 changed files with 103 additions and 96 deletions.
66 changes: 33 additions & 33 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.7', '3.8', '3.9', '3.10', '3.11' ]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
name: Python ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Set Up Chromedriver
run: |
sudo apt-get update
sudo apt-get --only-upgrade install google-chrome-stable
sudo apt-get -yqq install chromium-chromedriver
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[dev]
pip install "selenium<4.3.0"
pip install altair_saver vl-convert-python
pip install git+https://github.com/altair-viz/altair_viewer.git
- name: Test with pytest
run: |
pytest --doctest-modules altair
- name: Selected tests without vl-convert-python
run: |
pip uninstall vl-convert-python --yes
pytest -m save_engine --doctest-modules altair
- name: Selected tests without vl-convert-python and altair_saver
run: |
pip uninstall altair_saver --yes
pytest -m save_engine --doctest-modules altair
- name: Selected tests with vl-convert-python and without altair_saver
run: |
pip install vl-convert-python
pytest -m save_engine --doctest-modules altair
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Set Up Chromedriver
run: |
sudo apt-get update
sudo apt-get --only-upgrade install google-chrome-stable
sudo apt-get -yqq install chromium-chromedriver
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[dev]
pip install "selenium<4.3.0"
pip install altair_saver vl-convert-python
pip install git+https://github.com/altair-viz/altair_viewer.git
- name: Test with pytest
run: |
pytest --doctest-modules tests
- name: Selected tests without vl-convert-python
run: |
pip uninstall vl-convert-python --yes
pytest -m save_engine --doctest-modules tests
- name: Selected tests without vl-convert-python and altair_saver
run: |
pip uninstall altair_saver --yes
pytest -m save_engine --doctest-modules tests
- name: Selected tests with vl-convert-python and without altair_saver
run: |
pip install vl-convert-python
pytest -m save_engine --doctest-modules tests
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ install:
test :
black . --check
flake8 . --statistics
python -m pytest --pyargs --doctest-modules altair
python -m pytest --pyargs --doctest-modules tests

test-coverage:
python -m pytest --pyargs --doctest-modules --cov=altair --cov-report term altair
Expand Down
1 change: 0 additions & 1 deletion altair/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
__version__ = "4.3.0.dev0"

from .vegalite import *
from . import examples


def load_ipython_extension(ipython):
Expand Down
17 changes: 0 additions & 17 deletions altair/examples/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion altair/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import pandas as pd
import numpy as np

from .schemapi import SchemaBase, Undefined
from altair.utils.schemapi import SchemaBase, Undefined

try:
from pandas.api.types import infer_dtype as _infer_dtype
Expand Down
14 changes: 6 additions & 8 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
"sphinx.ext.coverage",
"sphinx.ext.githubpages",
"numpydoc.numpydoc",
"altair.sphinxext.altairplot",
"altair.sphinxext.altairgallery",
"altair.sphinxext.schematable",
"sphinxext.altairplot",
"sphinxext.altairgallery",
"sphinxext.schematable",
# "sphinxext.rediraffe",
]

Expand Down Expand Up @@ -84,7 +84,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'en'
language = "en"

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
Expand Down Expand Up @@ -154,12 +154,10 @@
"type": "fontawesome",
},
],
"header_links_before_dropdown": 6
"header_links_before_dropdown": 6,
}

html_context = {
"default_mode": "light"
}
html_context = {"default_mode": "light"}

# Add any paths that contain custom themes here, relative to this directory.
# html_theme_path = []
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exclude = '''
| build
| dist
| doc
| altair/examples
| tests/examples_arguments_syntax
| altair/vega/v\d*/schema
| altair/vegalite/v\d*/schema
)/
Expand Down
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ docutils
ipython
flake8
pytest
pytest-cov
sphinx
mistune<2.0.0 # necessary for m2r v0.2
m2r
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exclude =
.git,
build,
__pycache__,
altair/examples
tests/examples_arguments_syntax
altair/vega*/v?/schema

[metadata]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
create_generic_image,
)
from altair.utils.execeval import eval_block
from altair.examples import iter_examples
from tests.examples_arguments_syntax import iter_examples_arguments_syntax


EXAMPLE_MODULE = "altair.examples"
Expand Down Expand Up @@ -165,7 +165,7 @@ def save_example_pngs(examples, image_dir, make_thumbnails=True):
def populate_examples(**kwds):
"""Iterate through Altair examples and extract code"""

examples = sorted(iter_examples(), key=itemgetter("name"))
examples = sorted(iter_examples_arguments_syntax(), key=itemgetter("name"))

for example in examples:
docstring, category, code, lineno = get_docstring_and_rest(example["filename"])
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions tests/examples_arguments_syntax/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os


def iter_examples_arguments_syntax():
"""Iterate over the examples in this directory.
Each item is a dict with the following keys:
- "name" : the unique name of the example
- "filename" : the full file path to the example
"""
examples_arguments_syntax_dir = os.path.abspath(os.path.dirname(__file__))
for filename in os.listdir(examples_arguments_syntax_dir):
name, ext = os.path.splitext(filename)
if name.startswith("_") or ext != ".py":
continue
yield {
"name": name,
"filename": os.path.join(examples_arguments_syntax_dir, filename),
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,25 @@
source = data.stocks()

# Create a common chart object
chart = alt.Chart(source).transform_filter(
alt.datum.symbol != "IBM" # A reducation of the dataset to clarify our example. Not required.
).encode(
color=alt.Color("symbol", legend=None)
# Use `transform_filter` to reduce the dataset to clarify our example. Not required.
chart = (
alt.Chart(source)
.transform_filter(alt.datum.symbol != "IBM")
.encode(color=alt.Color("symbol", legend=None))
)

# Draw the line
line = chart.mark_line().encode(
x="date:T",
y="price:Q"
)
line = chart.mark_line().encode(x="date:T", y="price:Q")

# Use the `argmax` aggregate to limit the dataset to the final value
label = chart.encode(
x=alt.X('max(date):T'),
y=alt.Y('price:Q', aggregate=alt.ArgmaxDef(argmax='date')),
text='symbol'
x=alt.X("max(date):T"),
y=alt.Y("price:Q", aggregate=alt.ArgmaxDef(argmax="date")),
text="symbol",
)

# Create a text label
text = label.mark_text(align='left', dx=4)
text = label.mark_text(align="left", dx=4)

# Create a circle annotation
circle = label.mark_circle()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

from altair.utils.execeval import eval_block
from altair import examples
from tests import examples_arguments_syntax

try:
import altair_saver # noqa: F401
Expand All @@ -18,15 +18,17 @@


def iter_example_filenames():
for importer, modname, ispkg in pkgutil.iter_modules(examples.__path__):
for importer, modname, ispkg in pkgutil.iter_modules(
examples_arguments_syntax.__path__
):
if ispkg or modname.startswith("_"):
continue
yield modname + ".py"


@pytest.mark.parametrize("filename", iter_example_filenames())
def test_examples(filename: str):
source = pkgutil.get_data(examples.__name__, filename)
source = pkgutil.get_data(examples_arguments_syntax.__name__, filename)
chart = eval_block(source)

if chart is None:
Expand All @@ -50,7 +52,7 @@ def test_render_examples_to_png(engine, filename):
if "png" not in altair_saver.available_formats("vega-lite"):
pytest.skip("altair_saver not configured to save to png")

source = pkgutil.get_data(examples.__name__, filename)
source = pkgutil.get_data(examples_arguments_syntax.__name__, filename)
chart = eval_block(source)
out = io.BytesIO()
chart.save(out, format="png", engine=engine)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import pytest

from ... import expr
from .. import datum
from altair import expr
from altair import datum


def test_unary_operations():
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import pytest

import altair as alt
from .. import parse_shorthand, update_nested, infer_encoding_types
from ..core import infer_dtype
from altair.utils.core import parse_shorthand, update_nested, infer_encoding_types
from altair.utils.core import infer_dtype

FAKE_CHANNELS_MODULE = '''
"""Fake channels module for utility tests."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
import pandas as pd
from toolz import pipe

from ..data import limit_rows, MaxRowsError, sample, to_values, to_json, to_csv
from altair.utils.data import (
limit_rows,
MaxRowsError,
sample,
to_values,
to_json,
to_csv,
)


def _create_dataframe(N):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ..execeval import eval_block
from altair.utils.execeval import eval_block

HAS_RETURN = """
x = 4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from ..html import spec_to_html
from altair.utils.html import spec_to_html


@pytest.fixture
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

import altair as alt
from ..mimebundle import spec_to_mimebundle
from altair.utils.mimebundle import spec_to_mimebundle

try:
import altair_saver # noqa: F401
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ..plugin_registry import PluginRegistry
from altair.utils.plugin_registry import PluginRegistry
from typing import Callable


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import numpy as np

from ..schemapi import (
from altair.utils.schemapi import (
UndefinedType,
SchemaBase,
Undefined,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
import pandas as pd

from .. import infer_vegalite_type, sanitize_dataframe
from altair.utils import infer_vegalite_type, sanitize_dataframe


def test_infer_vegalite_type():
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added tests/vegalite/__init__.py
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pandas as pd

from .. import v3, v4, v5
from altair.vegalite import v3, v4, v5


@pytest.fixture
Expand Down
Empty file added tests/vegalite/v3/__init__.py
Empty file.
Empty file.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pandas as pd
import pytest

from .. import data as alt
from altair.vegalite.v3 import data as alt


@pytest.fixture
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added tests/vegalite/v4/__init__.py
Empty file.
Empty file.
File renamed without changes.
Loading

0 comments on commit 0d82108

Please sign in to comment.