Commit 75b10cfc authored by Jochem Bijlard's avatar Jochem Bijlard
Browse files

Fixes for tests

parent e1ce3f1b
...@@ -12,6 +12,10 @@ from fractalis.data.etls.transmart.etl_categorical import CategoricalETL ...@@ -12,6 +12,10 @@ from fractalis.data.etls.transmart.etl_categorical import CategoricalETL
class TestCategoricalETL: class TestCategoricalETL:
etl = CategoricalETL() etl = CategoricalETL()
descriptor = dict(
constraint='',
data_type='categorical'
)
def test_correct_handler(self): def test_correct_handler(self):
assert self.etl.can_handle(handler='transmart', assert self.etl.can_handle(handler='transmart',
...@@ -31,7 +35,7 @@ class TestCategoricalETL: ...@@ -31,7 +35,7 @@ class TestCategoricalETL:
content_type='application/json') content_type='application/json')
with pytest.raises(ValueError) as e: with pytest.raises(ValueError) as e:
self.etl.extract(server='http://foo.bar', self.etl.extract(server='http://foo.bar',
token='', descriptor={'path': ''}) token='', descriptor=self.descriptor)
assert '[400]' in e assert '[400]' in e
def test_extract_raises_readable_if_not_json(self): def test_extract_raises_readable_if_not_json(self):
...@@ -42,7 +46,7 @@ class TestCategoricalETL: ...@@ -42,7 +46,7 @@ class TestCategoricalETL:
content_type='application/json') content_type='application/json')
with pytest.raises(ValueError) as e: with pytest.raises(ValueError) as e:
self.etl.extract(server='http://foo.bar', self.etl.extract(server='http://foo.bar',
token='', descriptor={'path': ''}) token='', descriptor=self.descriptor)
assert 'unexpected data' in e assert 'unexpected data' in e
def test_extract_works_for_valid_input(self): def test_extract_works_for_valid_input(self):
...@@ -52,12 +56,12 @@ class TestCategoricalETL: ...@@ -52,12 +56,12 @@ class TestCategoricalETL:
status=200, status=200,
content_type='application/json') content_type='application/json')
raw_data = self.etl.extract(server='http://foo.bar', raw_data = self.etl.extract(server='http://foo.bar',
token='', descriptor={'path': ''}) token='', descriptor=self.descriptor)
assert isinstance(raw_data, dict) assert isinstance(raw_data, dict)
def test_transform_valid_input_correct_output(self): def test_transform_valid_input_correct_output(self):
body = { body = {
"cells": [{"inlineDimensions": ["292278994-08-16T23:00:00Z", None, "@"], "dimensionIndexes": [0, 0, 0, None, 0, None, None], "numericValue": 52.0}], # noqa: 501 "cells": [{"inlineDimensions": ["292278994-08-16T23:00:00Z", None, "@"], "dimensionIndexes": [0, 0, 0, None, 0, None, None], "stringValue": 'FOO'}], # noqa: 501
"dimensionElements": {"patient": [{"id": 1000421548, "deathDate": None, "birthDate": None, "race": None, "maritalStatus": None, "inTrialId": "3052", "age": 52, "trial": "GSE4382", "sexCd": None, "sex": "unknown", "religion": None}]} # noqa: E501 "dimensionElements": {"patient": [{"id": 1000421548, "deathDate": None, "birthDate": None, "race": None, "maritalStatus": None, "inTrialId": "3052", "age": 52, "trial": "GSE4382", "sexCd": None, "sex": "unknown", "religion": None}]} # noqa: E501
} }
with responses.RequestsMock() as response: with responses.RequestsMock() as response:
...@@ -66,8 +70,8 @@ class TestCategoricalETL: ...@@ -66,8 +70,8 @@ class TestCategoricalETL:
status=200, status=200,
content_type='application/json') content_type='application/json')
raw_data = self.etl.extract(server='http://foo.bar', raw_data = self.etl.extract(server='http://foo.bar',
token='', descriptor={'path': ''}) token='', descriptor=self.descriptor)
df = self.etl.transform(raw_data=raw_data, descriptor={'path': ''}) df = self.etl.transform(raw_data=raw_data, descriptor=self.descriptor)
assert df.shape == (1, 2) assert df.shape == (1, 3)
assert df.values.tolist() == [['3052', 52.0]] assert df.values.tolist() == [['3052', 'value', 'FOO']]
assert list(df) == ['id', 'value'] assert list(df) == ['id', 'feature', 'value']
...@@ -16,9 +16,9 @@ class TestHighdimlETL: ...@@ -16,9 +16,9 @@ class TestHighdimlETL:
def test_correct_handler(self): def test_correct_handler(self):
assert self.etl.can_handle(handler='transmart', assert self.etl.can_handle(handler='transmart',
descriptor={'data_type': 'highdim'}) descriptor={'data_type': 'numerical_array'})
assert not self.etl.can_handle(handler='ada', assert not self.etl.can_handle(handler='ada',
descriptor={'data_type': 'highdim'}) descriptor={'data_type': 'numerical_array'})
assert not self.etl.can_handle(handler='ada', assert not self.etl.can_handle(handler='ada',
descriptor={'data_type': 'categorical'}) descriptor={'data_type': 'categorical'})
assert not self.etl.can_handle(handler='ada', assert not self.etl.can_handle(handler='ada',
......
...@@ -12,6 +12,10 @@ from fractalis.data.etls.transmart.etl_numerical import NumericalETL ...@@ -12,6 +12,10 @@ from fractalis.data.etls.transmart.etl_numerical import NumericalETL
class TestNumericalETL: class TestNumericalETL:
etl = NumericalETL() etl = NumericalETL()
descriptor = dict(
constraint='',
data_type='numerical'
)
def test_correct_handler(self): def test_correct_handler(self):
assert self.etl.can_handle(handler='transmart', assert self.etl.can_handle(handler='transmart',
...@@ -31,7 +35,7 @@ class TestNumericalETL: ...@@ -31,7 +35,7 @@ class TestNumericalETL:
content_type='application/json') content_type='application/json')
with pytest.raises(ValueError) as e: with pytest.raises(ValueError) as e:
self.etl.extract(server='http://foo.bar', self.etl.extract(server='http://foo.bar',
token='', descriptor={'path': ''}) token='', descriptor=self.descriptor)
assert '[400]' in e assert '[400]' in e
def test_extract_raises_readable_if_not_json(self): def test_extract_raises_readable_if_not_json(self):
...@@ -42,7 +46,7 @@ class TestNumericalETL: ...@@ -42,7 +46,7 @@ class TestNumericalETL:
content_type='application/json') content_type='application/json')
with pytest.raises(ValueError) as e: with pytest.raises(ValueError) as e:
self.etl.extract(server='http://foo.bar', self.etl.extract(server='http://foo.bar',
token='', descriptor={'path': ''}) token='', descriptor=self.descriptor)
assert 'unexpected data' in e assert 'unexpected data' in e
def test_extract_works_for_valid_input(self): def test_extract_works_for_valid_input(self):
...@@ -52,7 +56,7 @@ class TestNumericalETL: ...@@ -52,7 +56,7 @@ class TestNumericalETL:
status=200, status=200,
content_type='application/json') content_type='application/json')
raw_data = self.etl.extract(server='http://foo.bar', raw_data = self.etl.extract(server='http://foo.bar',
token='', descriptor={'path': ''}) token='', descriptor=self.descriptor)
assert isinstance(raw_data, dict) assert isinstance(raw_data, dict)
def test_transform_valid_input_correct_output(self): def test_transform_valid_input_correct_output(self):
...@@ -65,9 +69,10 @@ class TestNumericalETL: ...@@ -65,9 +69,10 @@ class TestNumericalETL:
body=json.dumps(body), body=json.dumps(body),
status=200, status=200,
content_type='application/json') content_type='application/json')
raw_data = self.etl.extract(server='http://foo.bar', raw_data = self.etl.extract(server='http://foo.bar',
token='', descriptor={'path': ''}) token='', descriptor=self.descriptor)
df = self.etl.transform(raw_data=raw_data, descriptor={'path': ''}) df = self.etl.transform(raw_data=raw_data, descriptor=self.descriptor)
assert df.shape == (1, 2) assert df.shape == (1, 3)
assert df.values.tolist() == [['3052', 52.0]] assert df.values.tolist() == [['3052', 'value', 52.0]]
assert list(df) == ['id', 'value'] assert list(df) == ['id', 'feature', 'value']
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment