Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
V1NAY8 committed Oct 30, 2020
1 parent 31760fe commit 340666e
Show file tree
Hide file tree
Showing 91 changed files with 118 additions and 95 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Compiled python modules.
*.pyc
__pycache__/

# Setuptools distribution folder.
dist/
Expand All @@ -11,18 +12,19 @@ build/
docs/build/

# pytest results
eland/tests/dataframe/results/
test_eland/test_dataframe/results/*csv
result_images/


# Python egg metadata, regenerated from source files by setuptools.
/*.egg-info
eland.egg-info/

# PyCharm files
.idea/

# vscode files
.vscode/*
.vscode/

# pytest files
.pytest_cache/
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ currently using a minimum version of PyCharm 2019.2.4.
environment and run `pip install -r requirements-dev.txt`
- Setup Elasticsearch instance with docker `ELASTICSEARCH_VERSION=elasticsearch:7.x-SNAPSHOT .ci/run-elasticsearch.sh` and check `http://localhost:9200`
- Run
`python -m eland.tests.setup_tests` to setup test environment -*note
`python -m test_eland.setup_tests` to setup test environment -*note
this modifies Elasticsearch indices*
- Install local `eland` module (required to execute notebook tests)
`python setup.py install`
Expand Down
2 changes: 1 addition & 1 deletion docs/sphinx/development/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Configuring PyCharm And Running Tests
- Install development requirements. Open terminal in virtual
environment and run ``pip install -r requirements-dev.txt``
- Setup Elasticsearch instance (assumes ``localhost:9200``), and run
``python -m eland.tests.setup_tests`` to setup test environment -
``python -m test_eland/.setup_tests`` to setup test environment -
*note this modifies Elasticsearch indices*
- Run ``pytest --doctest-modules`` to validate install
- To test specific versions of Python use ``nox -s test-3.8``
Expand Down
20 changes: 8 additions & 12 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@
import nox

BASE_DIR = Path(__file__).parent
SOURCE_FILES = (
"setup.py",
"noxfile.py",
"eland/",
"docs/",
"utils/",
)
SOURCE_FILES = ("setup.py", "noxfile.py", "eland/", "docs/", "utils/", "test_eland/")

# Whenever type-hints are completed on a file it should
# be added here so that this file will continue to be checked
Expand Down Expand Up @@ -98,10 +92,12 @@ def lint(session):
@nox.session(python=["3.6", "3.7", "3.8"])
def test(session):
session.install("-r", "requirements-dev.txt")
session.run("python", "-m", "eland.tests.setup_tests")
session.run("python", "-m", "test_eland.setup_tests")
session.install(".")
session.run("pytest", "--doctest-modules", *(session.posargs or ("eland/",)))
session.run("pytest", "--nbval", "eland/tests/tests_notebook/")
session.run(
"pytest", "--doctest-modules", *(session.posargs or ("test_eland/", "eland/"))
)
session.run("pytest", "--nbval", "test_eland/tests_notebook/")

session.run(
"python",
Expand All @@ -113,7 +109,7 @@ def test(session):
"xgboost",
"lightgbm",
)
session.run("pytest", "eland/tests/ml/")
session.run("pytest", "test_eland/test_ml/")


@nox.session(reuse_venv=True)
Expand All @@ -132,7 +128,7 @@ def docs(session):
es = elasticsearch.Elasticsearch("localhost:9200")
es.info()
if not es.indices.exists("flights"):
session.run("python", "-m", "eland.tests.setup_tests")
session.run("python", "-m", "test_eland.setup_tests")
es_active = True
except Exception:
es_active = False
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion eland/tests/common.py → test_eland/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))

# Create pandas and eland data frames
from eland.tests import (
from test_eland import (
ECOMMERCE_DF_FILE_NAME,
ECOMMERCE_INDEX_NAME,
ES_TEST_CLIENT,
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.
2 changes: 1 addition & 1 deletion eland/tests/setup_tests.py → test_eland/setup_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from elasticsearch import helpers

from eland.common import es_version
from eland.tests import (
from test_eland import (
ECOMMERCE_FILE_NAME,
ECOMMERCE_INDEX_NAME,
ECOMMERCE_MAPPING,
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import pytest
from pandas.testing import assert_frame_equal, assert_series_equal

from eland.tests.common import TestData
from test_eland.common import TestData


class TestDataFrameAggs(TestData):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# File called _pytest for PyCharm compatability

import eland as ed
from eland.tests.common import ES_TEST_CLIENT, TestData
from test_eland.common import ES_TEST_CLIENT, TestData


class TestDataFrameBigMapping(TestData):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# File called _pytest for PyCharm compatability
from pandas.testing import assert_series_equal

from eland.tests.common import TestData
from test_eland.common import TestData


class TestDataFrameCount(TestData):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import eland as ed
from eland.field_mappings import FieldMappings
from eland.tests.common import (
from test_eland.common import (
ES_TEST_CLIENT,
TestData,
assert_pandas_eland_frame_equal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from pandas.testing import assert_frame_equal

from eland.tests.common import TestData
from test_eland.common import TestData


class TestDataFrameDescribe(TestData):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# File called _pytest for PyCharm compatibility


from eland.tests.common import TestData
from test_eland.common import TestData


class TestDataFrameDir(TestData):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import numpy as np
import pandas as pd

from eland.tests.common import assert_series_equal
from test_eland.common import assert_series_equal


class TestDataFrameDtypes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# File called _pytest for PyCharm compatability

from eland.tests.common import TestData
from test_eland.common import TestData


class TestEsMatch(TestData):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import pytest

from eland.tests.common import TestData, assert_eland_frame_equal
from test_eland.common import TestData, assert_eland_frame_equal


class TestDataEsQuery(TestData):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import pytest

from eland.tests.common import TestData
from test_eland.common import TestData


class TestDataFrameFilter(TestData):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import pytest
from pandas.testing import assert_frame_equal, assert_index_equal, assert_series_equal

from eland.tests.common import TestData
from test_eland.common import TestData


class TestGroupbyDataFrame(TestData):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# File called _pytest for PyCharm compatability

from eland.tests.common import TestData, assert_pandas_eland_frame_equal
from test_eland.common import TestData, assert_pandas_eland_frame_equal


class TestDataFrameHeadTail(TestData):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import pandas as pd
from pandas.testing import assert_frame_equal

from eland.tests.common import TestData
from test_eland.common import TestData


class TestDataFrameHist(TestData):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from io import StringIO

import eland as ed
from eland.tests import ES_TEST_CLIENT
from eland.tests.common import TestData
from test_eland import ES_TEST_CLIENT
from test_eland.common import TestData


class TestDataFrameInfo(TestData):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import eland as ed
from eland.query_compiler import QueryCompiler
from eland.tests import ES_TEST_CLIENT, FLIGHTS_INDEX_NAME
from test_eland import ES_TEST_CLIENT, FLIGHTS_INDEX_NAME


class TestDataFrameInit:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from pandas.testing import assert_index_equal

from eland.tests.common import TestData
from test_eland.common import TestData


class TestDataFrameKeys(TestData):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import pytest
from pandas.testing import assert_frame_equal, assert_series_equal

from eland.tests.common import TestData
from test_eland.common import TestData


class TestDataFrameMetrics(TestData):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from pandas.testing import assert_series_equal

from eland.tests.common import TestData
from test_eland.common import TestData


class TestDataFrameNUnique(TestData):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import pandas as pd

import eland as ed
from eland.tests.common import ES_TEST_CLIENT, TestData, assert_pandas_eland_frame_equal
from test_eland.common import ES_TEST_CLIENT, TestData, assert_pandas_eland_frame_equal


class TestDataFrameQuery(TestData):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import pytest

from eland.dataframe import DEFAULT_NUM_ROWS_DISPLAYED
from eland.tests.common import TestData, assert_pandas_eland_series_equal
from test_eland.common import TestData, assert_pandas_eland_series_equal


class TestDataFrameRepr(TestData):
Expand Down Expand Up @@ -159,6 +159,9 @@ def test_empty_dataframe_repr(self):
ed_ecom_r = repr(ed_ecom[ed_ecom["currency"] == "USD"])
pd_ecom_r = repr(pd_ecom[pd_ecom["currency"] == "USD"])

print(ed_ecom_r)
print(pd_ecom_r)

assert ed_ecom_r == pd_ecom_r

"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from pandas.testing import assert_frame_equal

from eland import eland_to_pandas
from eland.tests.common import TestData
from test_eland.common import TestData


class TestDataFrameSample(TestData):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# File called _pytest for PyCharm compatability
import numpy as np

from eland.tests.common import TestData, assert_pandas_eland_frame_equal
from test_eland.common import TestData, assert_pandas_eland_frame_equal


class TestDataFrameSelectDTypes(TestData):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# File called _pytest for PyCharm compatability

from eland.tests.common import TestData
from test_eland.common import TestData


class TestDataFrameShape(TestData):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
from pandas.testing import assert_frame_equal

import eland as ed
from eland.tests import ES_TEST_CLIENT, FLIGHTS_INDEX_NAME
from eland.tests.common import ROOT_DIR, TestData
from test_eland import ES_TEST_CLIENT, FLIGHTS_INDEX_NAME
from test_eland.common import ROOT_DIR, TestData


class TestDataFrameToCSV(TestData):
def test_to_csv_head(self):
results_file = ROOT_DIR + "/dataframe/results/test_to_csv_head.csv"
results_file = ROOT_DIR + "/test_dataframe/results/test_to_csv_head.csv"

ed_flights = self.ed_flights().head()
pd_flights = self.pd_flights().head()
Expand All @@ -50,7 +50,7 @@ def test_to_csv_head(self):
assert_frame_equal(pd_flights, pd_from_csv)

def test_to_csv_full(self):
results_file = ROOT_DIR + "/dataframe/results/test_to_csv_full.csv"
results_file = ROOT_DIR + "/test_dataframe/results/test_to_csv_full.csv"

# Test is slow as it's for the full dataset, but it is useful as it goes over 10000 docs
ed_flights = self.ed_flights()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import eland as ed
from eland.field_mappings import FieldMappings
from eland.tests.common import ES_TEST_CLIENT, TestData, assert_pandas_eland_frame_equal
from test_eland.common import ES_TEST_CLIENT, TestData, assert_pandas_eland_frame_equal


class TestDataFrameUtils(TestData):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from elasticsearch.helpers import BulkIndexError

from eland import DataFrame, pandas_to_eland
from eland.tests.common import (
from test_eland.common import (
ES_TEST_CLIENT,
assert_frame_equal,
assert_pandas_eland_frame_equal,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import pytest

from eland.field_mappings import FieldMappings
from eland.tests import ECOMMERCE_INDEX_NAME, ES_TEST_CLIENT
from eland.tests.common import TestData
from test_eland import ECOMMERCE_INDEX_NAME, ES_TEST_CLIENT
from test_eland.common import TestData


class TestAggregatables(TestData):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from datetime import datetime

from eland.field_mappings import FieldMappings
from eland.tests.common import ES_TEST_CLIENT, TestData
from test_eland.common import ES_TEST_CLIENT, TestData


class TestDateTime(TestData):
Expand Down

0 comments on commit 340666e

Please sign in to comment.