Skip to content

Commit

Permalink
Removing traces and starting migration of test suite to pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
mmerce committed Nov 18, 2022
1 parent c05bc05 commit b02f7e0
Show file tree
Hide file tree
Showing 73 changed files with 174 additions and 156 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/tests_01.yml
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: [3.8]
python: [3.10]
env:
BIGML_USERNAME: ${{ secrets.BIGML_USERNAME }}
BIGML_API_KEY: ${{ secrets.BIGML_API_KEY }}
Expand All @@ -30,8 +30,10 @@ jobs:
- run: |
pip install .[topics]
- name: Run tests *01 02 04 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 41 45 99 38 99*
- name: Run tests *01 04 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 41 45 99 38 99*
run: |
export TESTS=$(for t in "01" "02" "04" "06" "07" "08" "09" "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "20" "21" "41" "38" "99"; do ls bigml/tests/*$t*.py;done|paste -sd ",")
pip3 install nose
pip3 install pytest
export TESTS=$(for t in "01" "04" "06" "07" "08" "09" "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "20" "21" "41" "38" "99"; do ls bigml/tests/*$t*.py;done|paste -sd " ")
echo $TESTS
python setup.py nosetests --nocapture --tests=$TESTS
pytest -s $TESTS
8 changes: 5 additions & 3 deletions .github/workflows/tests_05.yml
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: [3.8]
python: [3.10]
env:
BIGML_USERNAME: ${{ secrets.BIGML_USERNAME }}
BIGML_API_KEY: ${{ secrets.BIGML_API_KEY }}
Expand All @@ -31,6 +31,8 @@ jobs:
- name: Run tests *01 05 40 45 99*
run: |
export TESTS=$(for t in "05" "40" "45" "99"; do ls bigml/tests/*$t*.py;done|paste -sd ",")
pip3 install nose
pip3 install pytest
export TESTS=$(for t in "05" "40" "45" "99"; do ls bigml/tests/*$t*.py;done|paste -sd " ")
echo $TESTS
python setup.py nosetests --nocapture --tests=$TESTS
pytest -s $TESTS
8 changes: 5 additions & 3 deletions .github/workflows/tests_22.yml
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: [3.8]
python: [3.10]
env:
BIGML_USERNAME: ${{ secrets.BIGML_USERNAME }}
BIGML_API_KEY: ${{ secrets.BIGML_API_KEY }}
Expand All @@ -32,6 +32,8 @@ jobs:
- name: Run tests *22 24 25 26 27 28 29 30 31 32 34 39 43 42 44 99*
run: |
export TESTS=$(for t in "22" "24" "25" "26" "27" "28" "29" "30" "31" "32" "34" "39" "43" "42" "44" "99"; do ls bigml/tests/*$t*.py;done|paste -sd ",")
pip3 install nose
pip3 install pytest
export TESTS=$(for t in "22" "24" "25" "26" "27" "28" "29" "30" "31" "32" "34" "39" "43" "42" "44" "99"; do ls bigml/tests/*$t*.py;done|paste -sd " ")
echo $TESTS
python setup.py nosetests --nocapture --tests=$TESTS
pytest -s $TESTS
8 changes: 5 additions & 3 deletions .github/workflows/tests_23.yml
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: [3.8]
python: [3.10]
env:
BIGML_USERNAME: ${{ secrets.BIGML_USERNAME }}
BIGML_API_KEY: ${{ secrets.BIGML_API_KEY }}
Expand All @@ -32,6 +32,8 @@ jobs:
- name: Run tests *23 03 37 35 47 48 49 99*
run: |
export TESTS=$(for t in "23" "03" "37" "35" "47" "48" "49" "99"; do ls bigml/tests/*$t*.py;done|paste -sd ",")
pip3 install nose
pip3 install pytest
export TESTS=$(for t in "23" "03" "37" "35" "47" "48" "49" "99"; do ls bigml/tests/*$t*.py;done|paste -sd " ")
echo $TESTS
python setup.py nosetests --nocapture --tests=$TESTS
pytest -s $TESTS
8 changes: 5 additions & 3 deletions .github/workflows/tests_36.yml
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: [3.8]
python: [3.10]
env:
BIGML_USERNAME: ${{ secrets.BIGML_USERNAME }}
BIGML_API_KEY: ${{ secrets.BIGML_API_KEY }}
Expand All @@ -32,6 +32,8 @@ jobs:
- name: Run tests *36 33 99*
run: |
export TESTS=$(for t in "36" "33" "99"; do ls bigml/tests/*$t*.py;done|paste -sd ",")
pip3 install nose
pip3 install pytest
export TESTS=$(for t in "36" "33" "99"; do ls bigml/tests/*$t*.py;done|paste -sd " ")
echo $TESTS
python setup.py nosetests --nocapture --tests=$TESTS
pytest -s $TESTS
6 changes: 6 additions & 0 deletions HISTORY.rst
Expand Up @@ -3,6 +3,12 @@
History
-------

9.1.1 (2022-11-18)
------------------

- Removing traces and refactoring Flatline interpreter invocation.
- Migrating tests to pytest.

9.1.0 (2022-11-09)
------------------

Expand Down
7 changes: 6 additions & 1 deletion bigml/dataset.py
Expand Up @@ -177,16 +177,21 @@ def _transform(self, input_arrays):
names = transformation.get("names", [])
out_headers.extend(names)
# evaluating first to raise an alert if the expression is failing
"""
check = Flatline.interpreter.evaluate_sexp(
expr, fields, True).valueOf()
"""
check = Flatline.check_lisp(expr, fields)
if "error" in check:
raise ValueError(check["error"])
if expr == '(all)':
new_input_arrays = input_arrays.copy()
continue
print("*** expr", expr)
"""
new_input = Flatline.interpreter.eval_and_apply_sexp(
expr, fields, input_arrays)
"""
new_input = Flatline.apply_lisp(expr, input_arrays, self)
for index, _ in enumerate(new_input):
try:
new_input_arrays[index]
Expand Down
14 changes: 5 additions & 9 deletions bigml/flatline.py
Expand Up @@ -105,30 +105,26 @@ def defined_functions():
return Flatline.interpreter.defined_primitives

@staticmethod
def check_lisp(sexp, dataset=None):
def check_lisp(sexp, fields=None):
"""Checks whether the given lisp s-expression is valid.
Any operations referring to a dataset's fields will use the
information found in the provided dataset, which should have
the structure of the 'object' component of a BigML dataset
resource.
information found in fields structure.
"""
r = Flatline.interpreter.evaluate_sexp(sexp, dataset)
r.pop('mapper', None)
r = Flatline.interpreter.evaluate_sexp(sexp, fields, True).valueOf()
return r

@staticmethod
def check_json(json_sexp, dataset=None):
def check_json(json_sexp, fields=None):
"""Checks whether the given JSON s-expression is valid.
Works like `check_lisp` (which see), but taking a JSON
expression represented as a native Python list instead of a
Lisp sexp string.
"""
r = Flatline.interpreter.evaluate_js(json_sexp, dataset)
r.pop('mapper', None)
r = Flatline.interpreter.evaluate_js(json_sexp, fields).valueOf()
return r

@staticmethod
Expand Down
12 changes: 6 additions & 6 deletions bigml/tests/compare_predictions_steps.py
Expand Up @@ -149,7 +149,7 @@ def i_create_a_local_regions_prediction(step, image_file=None):
def i_create_a_local_prediction_op(step, data=None, operating_point=None):
if data is None:
data = "{}"
assert_is_not_none(operating_point)
assert operating_point is not None
data = json.loads(data)
world.local_prediction = world.local_model.predict( \
data, operating_point=operating_point)
Expand All @@ -159,7 +159,7 @@ def i_create_a_local_prediction_op(step, data=None, operating_point=None):
def i_create_a_local_ensemble_prediction_op(step, data=None, operating_point=None):
if data is None:
data = "{}"
assert_is_not_none(operating_point)
assert operating_point is not None
data = json.loads(data)
world.local_prediction = world.local_ensemble.predict( \
data, operating_point=operating_point)
Expand Down Expand Up @@ -547,7 +547,7 @@ def the_local_association_set_is_like_file(step, filename):
def i_create_a_local_prediction_op_kind(step, data=None, operating_kind=None):
if data is None:
data = "{}"
assert_is_not_none(operating_kind)
assert operating_kind is not None
data = json.loads(data)
world.local_prediction = world.local_model.predict( \
data, operating_kind=operating_kind)
Expand All @@ -558,7 +558,7 @@ def i_create_a_local_ensemble_prediction_op_kind( \
step, data=None, operating_kind=None):
if data is None:
data = "{}"
assert_is_not_none(operating_kind)
assert operating_kind is not None
data = json.loads(data)
world.local_prediction = world.local_ensemble.predict( \
data, operating_kind=operating_kind)
Expand All @@ -569,7 +569,7 @@ def i_create_a_local_deepnet_prediction_op_kind( \
step, data=None, operating_kind=None):
if data is None:
data = "{}"
assert_is_not_none(operating_kind)
assert operating_kind is not None
data = json.loads(data)
world.local_prediction = world.local_model.predict( \
data, operating_kind=operating_kind)
Expand All @@ -580,7 +580,7 @@ def i_create_a_local_logistic_prediction_op_kind( \
step, data=None, operating_kind=None):
if data is None:
data = "{}"
assert_is_not_none(operating_kind)
assert operating_kind is not None
data = json.loads(data)
world.local_prediction = world.local_model.predict( \
data, operating_kind=operating_kind)
Expand Down
2 changes: 1 addition & 1 deletion bigml/tests/create_evaluation_steps.py
Expand Up @@ -103,5 +103,5 @@ def the_measured_measure_is_value(step, measure, value):

#@step(r'the measured "(.*)" is greater than (\d+\.*\d*)')
def the_measured_measure_is_greater_value(step, measure, value):
assert_greater(world.evaluation['result']['model'][measure] + 0.0,
assert (world.evaluation['result']['model'][measure] + 0.0 >
float(value))
2 changes: 1 addition & 1 deletion bigml/tests/create_pca_steps_bck.py
Expand Up @@ -82,7 +82,7 @@ def wait_until_pca_status_code_is(step, code1, code2, secs):
while (status['code'] != int(code1) and
status['code'] != int(code2)):
time.sleep(3)
assert_less(datetime.utcnow() - start, timedelta(seconds=delta))
assert datetime.utcnow() - start < timedelta(seconds=delta)
i_get_the_pca(step, pca_id)
status = get_status(world.pca)
eq_(status['code'], int(code1))
Expand Down
10 changes: 5 additions & 5 deletions bigml/tests/create_prediction_steps.py
Expand Up @@ -43,7 +43,7 @@ def i_create_a_prediction(step, data=None):
def i_create_a_prediction_op(step, data=None, operating_point=None):
if data is None:
data = "{}"
assert_is_not_none(operating_point)
assert operating_point is not None
model = world.model['resource']
data = json.loads(data)
resource = world.api.create_prediction( \
Expand All @@ -58,7 +58,7 @@ def i_create_a_prediction_op(step, data=None, operating_point=None):
def i_create_an_ensemble_prediction_op(step, data=None, operating_point=None):
if data is None:
data = "{}"
assert_is_not_none(operating_point)
assert operating_point is not None
ensemble = world.ensemble['resource']
data = json.loads(data)
resource = world.api.create_prediction( \
Expand All @@ -73,7 +73,7 @@ def i_create_an_ensemble_prediction_op(step, data=None, operating_point=None):
def i_create_a_fusion_prediction_op(step, data=None, operating_point=None):
if data is None:
data = "{}"
assert_is_not_none(operating_point)
assert operating_point is not None
fusion = world.fusion['resource']
data = json.loads(data)
resource = world.api.create_prediction( \
Expand Down Expand Up @@ -323,7 +323,7 @@ def the_fusion_probability_is(step, probability):
def i_create_a_prediction_op_kind(step, data=None, operating_kind=None):
if data is None:
data = "{}"
assert_is_not_none(operating_kind)
assert operating_kind is not None
model = world.model['resource']
data = json.loads(data)
resource = world.api.create_prediction( \
Expand All @@ -338,7 +338,7 @@ def i_create_a_prediction_op_kind(step, data=None, operating_kind=None):
def i_create_an_ensemble_prediction_op_kind(step, data=None, operating_kind=None):
if data is None:
data = "{}"
assert_is_not_none(operating_kind)
assert operating_kind is not None
ensemble = world.ensemble['resource']
data = json.loads(data)
resource = world.api.create_prediction( \
Expand Down
2 changes: 1 addition & 1 deletion bigml/tests/delete_project_steps.py
Expand Up @@ -33,7 +33,7 @@ def wait_until_project_deleted(step, secs):
resource = world.api.get_project(project_id)
while (resource['code'] == HTTP_OK):
time.sleep(3)
assert_less(datetime.utcnow() - start, timedelta(seconds=int(secs)))
assert datetime.utcnow() - start < timedelta(seconds=int(secs))
resource = world.api.get_project(project_id)
eq_(resource['code'], HTTP_NOT_FOUND)
world.projects.remove(project_id)
2 changes: 1 addition & 1 deletion bigml/tests/read_dataset_steps.py
Expand Up @@ -37,5 +37,5 @@ def i_get_the_errors_values(step):

#@step(r'the (missing values counts|error counts) dict is "(.*)"')
def i_get_the_properties_values(step, text, properties_dict):
assert_not_equal(None, properties_dict)
assert None != properties_dict
eq_(world.step_result, json.loads(properties_dict))
2 changes: 1 addition & 1 deletion bigml/tests/read_resource_steps.py
Expand Up @@ -40,7 +40,7 @@ def wait_until_status_code_is(code1, code2, secs, resource_info):
count += 1
resource_type = get_resource_type(resource_info["resource"])
logged_wait(start, delta, count, resource_type, status=status)
assert_less((datetime.utcnow() - start).seconds, delta)
assert (datetime.utcnow() - start).seconds < delta
resource_info = world.get_minimal_resource(
resource_info['resource']).get("object")
status = get_status(resource_info)
Expand Down
4 changes: 2 additions & 2 deletions bigml/tests/test_01_prediction.py
Expand Up @@ -33,13 +33,13 @@

class TestPrediction(object):

def setup(self):
def setup_method(self):
"""
Debug information
"""
print("\n-------------------\nTests in: %s\n" % __name__)

def teardown(self):
def teardown_method(self):
"""
Debug information
"""
Expand Down
4 changes: 2 additions & 2 deletions bigml/tests/test_03_local_prediction.py
Expand Up @@ -29,13 +29,13 @@

class TestLocalPrediction(object):

def setup(self):
def setup_method(self):
"""
Debug information
"""
print("\n-------------------\nTests in: %s\n" % __name__)

def teardown(self):
def teardown_method(self):
"""
Debug information
"""
Expand Down
4 changes: 2 additions & 2 deletions bigml/tests/test_04_multivote_prediction.py
Expand Up @@ -27,13 +27,13 @@

class TestMultiVotePrediction(object):

def setup(self):
def setup_method(self):
"""
Debug information
"""
print("\n-------------------\nTests in: %s\n" % __name__)

def teardown(self):
def teardown_method(self):
"""
Debug information
"""
Expand Down
4 changes: 2 additions & 2 deletions bigml/tests/test_05_compare_predictions.py
Expand Up @@ -34,13 +34,13 @@

class TestComparePrediction(object):

def setup(self):
def setup_method(self):
"""
Debug information
"""
print("\n-------------------\nTests in: %s\n" % __name__)

def teardown(self):
def teardown_method(self):
"""
Debug information
"""
Expand Down
4 changes: 2 additions & 2 deletions bigml/tests/test_05_compare_predictions_b.py
Expand Up @@ -35,13 +35,13 @@

class TestComparePrediction(object):

def setup(self):
def setup_method(self):
"""
Debug information
"""
print("\n-------------------\nTests in: %s\n" % __name__)

def teardown(self):
def teardown_method(self):
"""
Debug information
"""
Expand Down

0 comments on commit b02f7e0

Please sign in to comment.