diff options
Diffstat (limited to 'tests/test_tableflow.py')
-rw-r--r-- | tests/test_tableflow.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/test_tableflow.py b/tests/test_tableflow.py new file mode 100644 index 0000000..6b16046 --- /dev/null +++ b/tests/test_tableflow.py @@ -0,0 +1,50 @@ +import pytest +import qolab.tableflow as tblfl +import pandas as pd + +def test_noinputs(): + assert tblfl.loadInOutTables() == (None, None) + assert tblfl.loadInOutTables(inputFileName=None, outputFileName="non_existing_file") == (None, None) + +def test_wrong_comment(): + with pytest.raises(Exception) as exc_info: + # should raise ParserError + tblfl.loadInOutTables(inputFileName='tests/tableflow_test_data/tableIn1.csv', outputFileName=None, comment='%') + +def test_right_comment(): + tIn,tOut = tblfl.loadInOutTables(inputFileName='tests/tableflow_test_data/tableIn1.csv', outputFileName=None, comment='#') + assert type(tIn) == pd.core.frame.DataFrame + +def test_right_comment(): + tIn,tOut = tblfl.loadInOutTables(inputFileName='tests/tableflow_test_data/tableIn1.csv', outputFileName=None, comment='#') + assert type(tIn) == pd.core.frame.DataFrame + + +def test_for_existing_row(): + tbl1 = pd.DataFrame( {'a':[1,2,3], 'b':[1,4,6]}) + r = pd.Series({'a':2, 'b':4}) + assert tblfl.ilocRowOrAdd(tbl1, r) == 1 + +def test_for_existing_row_with_NA(): + # NA in both table and raw should return a hit + tbl1 = pd.DataFrame( {'a':[1,2,3], 'b':[1,pd.NA,6]}) + r = pd.Series({'a':2, 'b':pd.NA}) + assert tblfl.ilocRowOrAdd(tbl1, r) == 1 + + # should insert new row + tbl1 = pd.DataFrame( {'a':[1,2,3], 'b':[1,4,6]}) + r = pd.Series({'a':2, 'b':pd.NA}) + assert tblfl.ilocRowOrAdd(tbl1, r) == 3 + + # should insert new row + tbl1 = pd.DataFrame( {'a':[1,2,3], 'b':[1,4,6]}) + r = pd.Series({'a':2, 'b':pd.NA}) + assert tblfl.ilocRowOrAdd(tbl1, r) == 3 + +def test_for_nonexisting_row_and_its_insertion(): + tbl1 = pd.DataFrame( {'a':[1,2,3], 'b':[1,4,6]}) + r = pd.Series({'a':2, 'b':10}) + assert len(tbl1) == 3 + assert tblfl.ilocRowOrAdd(tbl1, r) == 3 + assert len(tbl1) == 4 + |