|
1 | 1 | import os |
2 | 2 |
|
| 3 | +import pytest |
| 4 | + |
3 | 5 | from mfr.extensions.tabular.libs import panda_tools |
4 | 6 |
|
5 | 7 | BASE = os.path.dirname(os.path.abspath(__file__)) |
@@ -31,11 +33,35 @@ def test_tsv_pandas(self): |
31 | 33 | assert sheet[0][0] == {'field': 'one\ttwo\tthree', 'id': 'one\ttwo\tthree', 'name': 'one\ttwo\tthree', 'sortable': True} |
32 | 34 | assert sheet[1][0] == {'one\ttwo\tthree': 'a\tb\tc'} |
33 | 35 |
|
34 | | - # def test_dta_pandas(): |
35 | | - # with open('mfr_tabular/tests/fixtures/test.dta') as fp: |
36 | | - # headers, data = panda_tools.dta_pandas(fp) |
| 36 | + def test_invalid_dta(self): |
| 37 | + with open(os.path.join(BASE, 'files', 'invalid.dta')) as fp: |
| 38 | + with pytest.raises(ValueError): |
| 39 | + panda_tools.dta_pandas(fp) |
| 40 | + |
| 41 | + def test_dta_pandas(self): |
| 42 | + with open(os.path.join(BASE, 'files', 'test.dta')) as fp: |
| 43 | + sheets = panda_tools.dta_pandas(fp) |
37 | 44 |
|
38 | | - # assert headers[0] == {'field': 'one', 'id': 'one', 'name': 'one'} |
39 | | - # assert data[0] == {'one': 'a', 'two': 'b', 'three': 'c'} |
40 | | - # assert len(data) is 2 |
41 | | - # assert len(headers) is 3 |
| 45 | + sheet = sheets.popitem()[1] |
| 46 | + assert sheet == ([{'id': 'Actor', 'name': 'Actor', 'field': 'Actor', 'sortable': True}, |
| 47 | + {'id': 'IMDBscore', 'name': 'IMDBscore', 'field': 'IMDBscore', 'sortable': True}], |
| 48 | + [{'Actor': '1', 'IMDBscore': 6.6}, {'Actor': '1', 'IMDBscore': 6.5}, |
| 49 | + {'Actor': '1', 'IMDBscore': 7.3}, {'Actor': '1', 'IMDBscore': 7.8}, |
| 50 | + {'Actor': '1', 'IMDBscore': 6.3}, {'Actor': '1', 'IMDBscore': 6.6}, |
| 51 | + {'Actor': '1', 'IMDBscore': 6.1}, {'Actor': '1', 'IMDBscore': 7.1}, |
| 52 | + {'Actor': '1', 'IMDBscore': 5.7}, {'Actor': '1', 'IMDBscore': 5.7}, |
| 53 | + {'Actor': '1', 'IMDBscore': 7.1}, {'Actor': '1', 'IMDBscore': 7.6}, |
| 54 | + {'Actor': '1', 'IMDBscore': 7.1}, {'Actor': '1', 'IMDBscore': 3.8}, |
| 55 | + {'Actor': '1', 'IMDBscore': 8.0}, {'Actor': '1', 'IMDBscore': 4.7}, |
| 56 | + {'Actor': '1', 'IMDBscore': 6.5}, {'Actor': '1', 'IMDBscore': 7.6}, |
| 57 | + {'Actor': '1', 'IMDBscore': 6.3}, {'Actor': '1', 'IMDBscore': 5.4}, |
| 58 | + {'Actor': '2', 'IMDBscore': 7.1}, {'Actor': '2', 'IMDBscore': 7.3}, |
| 59 | + {'Actor': '2', 'IMDBscore': 6.2}, {'Actor': '2', 'IMDBscore': 7.4}, |
| 60 | + {'Actor': '2', 'IMDBscore': 7.5}, {'Actor': '2', 'IMDBscore': 6.7}, |
| 61 | + {'Actor': '2', 'IMDBscore': 6.2}, {'Actor': '2', 'IMDBscore': 4.7}, |
| 62 | + {'Actor': '2', 'IMDBscore': 6.5}, {'Actor': '2', 'IMDBscore': 5.5}, |
| 63 | + {'Actor': '2', 'IMDBscore': 5.4}, {'Actor': '2', 'IMDBscore': 7.7}, |
| 64 | + {'Actor': '2', 'IMDBscore': 7.1}, {'Actor': '2', 'IMDBscore': 6.1}, |
| 65 | + {'Actor': '2', 'IMDBscore': 6.7}, {'Actor': '2', 'IMDBscore': 7.0}, |
| 66 | + {'Actor': '2', 'IMDBscore': 5.8}, {'Actor': '2', 'IMDBscore': 4.1}, |
| 67 | + {'Actor': '2', 'IMDBscore': 5.7}, {'Actor': '2', 'IMDBscore': 6.1}]) |
0 commit comments