-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add strategies and data dictionary tests
- Loading branch information
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"Common fixtures" | ||
|
||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
import arcmapper | ||
|
||
dictionary_file = str(Path(__file__).parent / "data" / "ccpuk_dictionary.csv") | ||
arc_file = str(Path(__file__).parent / "data" / "ARCH.csv") | ||
|
||
@pytest.fixture(scope="session") | ||
def arc_schema(): | ||
return arcmapper.read_arc_schema(arc_file) | ||
|
||
@pytest.fixture(scope="session") | ||
def data_dictionary(): | ||
return arcmapper.read_data_dictionary(dictionary_file, description_field="Field Label", | ||
response_field="Choices, Calculations, OR Slider Labels", response_func="redcap") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import pandas as pd | ||
|
||
from arcmapper.dictionary import read_from_jsonschema | ||
|
||
|
||
EXAMPLE_JSON_SCHEMA = """{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"properties": { | ||
"category": { | ||
"type": "string", | ||
"enum": ["option1", "option2", "option3"], | ||
"description": "category of the variable" | ||
}, | ||
"value": { | ||
"type": "number", | ||
"description": "default value of variable" | ||
}, | ||
"full_name": { | ||
"type": "string", | ||
"description": "full name of variable" | ||
} | ||
}, | ||
"required": ["category", "value", "full_name"] | ||
}""" | ||
|
||
def test_read_data_dictionary(data_dictionary): | ||
assert data_dictionary.columns.tolist()== ["variable", "description", "responses", "type"] | ||
|
||
|
||
def test_read_from_jsonschema(): | ||
dd = read_from_jsonschema(EXAMPLE_JSON_SCHEMA) | ||
print(dd) | ||
expected = pd.DataFrame({'variable': ["category", "value", "full_name"], | ||
'description': ['category of the variable', 'default value of variable', 'full name of variable'], | ||
'responses': [[('option1', 'option1'),('option2', 'option2'),('option3', 'option3')], None, None], | ||
'type': ['categorical', 'number', 'string']}) | ||
assert dd.equals(expected) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from pathlib import Path | ||
import numpy as np | ||
|
||
from arcmapper.strategies import map, get_categorical_mapping | ||
|
||
dictionary_file = Path(__file__).parent / "data" / "ccpuk_dictionary.csv" | ||
arc_file = Path(__file__).parent / "data" / "ARCH.csv" | ||
|
||
def test_get_categorical_mapping(): | ||
sim = np.array([[0.1, 0.8], [0.9, 0.1]]) | ||
target = ["male", "female"] | ||
source = ["femme", "homme"] | ||
assert get_categorical_mapping(source, target, sim) == {"femme": "female", "homme": "male"} | ||
|
||
|
||
def test_tf_idf(data_dictionary, arc_schema): | ||
map("tf-idf", data_dictionary, arc_schema, num_matches=3) | ||
|
||
|