Skip to content

Commit

Permalink
Add tests for HS labels with missing
Browse files Browse the repository at this point in the history
- Add test for a univariate CAT with missing categories and H&S,
  ensure that the labels of the missings are not returned
- Restructure tests, prepare for the more signifficant refactor
  • Loading branch information
slobodan-ilic committed Apr 12, 2018
1 parent 1f1ec74 commit 926cc8a
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/integration/fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,4 @@ def _load(cube_file):
PETS_X_FRUIT_HS = _load('pets-x-fruit-hs.json')
VALUE_SERVICES = _load('value-added-services.json')
LETTERS_X_PETS_HS = _load('letters-x-pets-hs.json')
MISSING_CAT_HS = _load('missing-cat-hs.json')
166 changes: 166 additions & 0 deletions tests/integration/fixtures/cubes/missing-cat-hs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
{
"element": "shoji:view",
"self": "https://app.crunch.io/api/datasets/1ac271769c1b4af381e8437717afbb56/cube/?filter=%5B%5D&query=%7B%22dimensions%22:%5B%7B%22variable%22:%22https:%2F%2Fapp.crunch.io%2Fapi%2Fdatasets%2F1ac271769c1b4af381e8437717afbb56%2Fvariables%2F000045%2F%22%7D%5D,%22measures%22:%7B%22count%22:%7B%22function%22:%22cube_count%22,%22args%22:%5B%5D%7D%7D,%22weight%22:null%7D",
"value": {
"query": {
"measures": {
"count": {
"function": "cube_count",
"args": []
}
},
"dimensions": [
{
"variable": "https://app.crunch.io/api/datasets/1ac271769c1b4af381e8437717afbb56/variables/000045/"
}
],
"weight": null
},
"query_environment": {
"filter": []
},
"result": {
"dimensions": [
{
"derived": false,
"references": {
"alias": "exitpoll16",
"view": {
"show_counts": false,
"show_numeric_values": false,
"transform": {
"insertions": [
{
"function": "subtotal",
"args": [
1,
2,
3,
4
],
"name": "Whites",
"anchor": "top"
}
]
},
"include_missing": false,
"column_width": null
},
"description": "National Exit Poll Demographic Groups",
"name": "exitpoll16"
},
"type": {
"ordinal": false,
"class": "categorical",
"categories": [
{
"numeric_value": 7,
"id": 7,
"name": "Non-voters",
"missing": true
},
{
"numeric_value": 1,
"id": 1,
"name": "White college women voters",
"missing": false
},
{
"numeric_value": 2,
"id": 2,
"name": "White non-college women voters",
"missing": false
},
{
"numeric_value": 3,
"id": 3,
"name": "White college men voters",
"missing": false
},
{
"numeric_value": 4,
"id": 4,
"name": "White non-college men voters",
"missing": false
},
{
"numeric_value": 5,
"id": 5,
"name": "Black voters",
"missing": false
},
{
"numeric_value": 6,
"id": 6,
"name": "Latino and other voters",
"missing": false
},
{
"numeric_value": 32766,
"id": 32766,
"name": "skipped",
"missing": true
},
{
"numeric_value": 32767,
"id": 32767,
"name": "not asked",
"missing": true
},
{
"numeric_value": null,
"id": -1,
"name": "No Data",
"missing": true
}
]
}
}
],
"missing": 324,
"measures": {
"count": {
"data": [
324,
181,
275,
171,
251,
131,
167,
0,
0,
0
],
"n_missing": 324,
"metadata": {
"references": {},
"derived": true,
"type": {
"integer": true,
"missing_rules": {},
"missing_reasons": {
"No Data": -1
},
"class": "numeric"
}
}
}
},
"element": "crunch:cube",
"counts": [
324,
181,
275,
171,
251,
131,
167,
0,
0,
0
],
"n": 1500
}
}
}
25 changes: 25 additions & 0 deletions tests/integration/test_pruning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from unittest import TestCase
from mock import patch
import numpy as np

from cr.cube.crunch_cube import CrunchCube

from .fixtures import MISSING_CAT_HS


class TestCrunchCube(TestCase):
def test_missing_cat_hs_labels(self):
cube = CrunchCube(MISSING_CAT_HS)

# Don't expect the missing category "Non voters"
expected = [[
'Whites',
'White college women voters',
'White non-college women voters',
'White college men voters',
'White non-college men voters',
'Black voters',
'Latino and other voters',
]]
actual = cube.labels(include_transforms_for_dims=[0])
assert actual == expected

0 comments on commit 926cc8a

Please sign in to comment.