def test_csv_input_utf8(self, tmpdir):
     main = tmpdir.join("main.csv")
     main.write_text("colA\néαГ😼𝒞人", encoding="utf8")
     csvinput = CSVInput(input_name=tmpdir.strpath)  # defaults to utf8
     csvinput.read_sheets()
     assert list(csvinput.get_sheet_lines("main")) == [{"colA": "éαГ😼𝒞人"}]
     assert csvinput.sub_sheet_names == ["main"]
    def test_csv_input(self, tmpdir):
        main = tmpdir.join("main.csv")
        main.write("colA,colB\ncell1,cell2\ncell3,cell4")
        subsheet = tmpdir.join("subsheet.csv")
        subsheet.write("colC,colD\ncell5,cell6\ncell7,cell8")

        csvinput = CSVInput(input_name=tmpdir.strpath)

        csvinput.read_sheets()

        assert csvinput.sub_sheet_names == ["main", "subsheet"]
        assert list(csvinput.get_sheet_lines("main")) == [
            {
                "colA": "cell1",
                "colB": "cell2"
            },
            {
                "colA": "cell3",
                "colB": "cell4"
            },
        ]
        assert list(csvinput.get_sheet_lines("subsheet")) == [
            {
                "colC": "cell5",
                "colD": "cell6"
            },
            {
                "colC": "cell7",
                "colD": "cell8"
            },
        ]
Example #3
0
 def test_csv_no_directory(self):
     csvinput = CSVInput(input_name='nonesensedirectory', main_sheet_name='main')
     if sys.version > '3':
         with pytest.raises(FileNotFoundError):
             csvinput.read_sheets()
     else:
         with pytest.raises(OSError):
             csvinput.read_sheets()
Example #4
0
 def test_csv_input_utf8(self, tmpdir):
     main = tmpdir.join('main.csv')
     main.write_text('colA\néαГ😼𝒞人', encoding='utf8')
     csvinput = CSVInput(input_name=tmpdir.strpath, main_sheet_name='main')  # defaults to utf8
     csvinput.read_sheets()
     assert list(csvinput.get_main_sheet_lines()) == \
         [{'colA': 'éαГ😼𝒞人'}]
     assert csvinput.sub_sheet_names == []
 def test_csv_input_latin1(self, tmpdir):
     main = tmpdir.join("main.csv")
     main.write_text("colA\né", encoding="latin-1")
     csvinput = CSVInput(input_name=tmpdir.strpath)
     csvinput.encoding = "latin-1"
     csvinput.read_sheets()
     assert list(csvinput.get_sheet_lines("main")) == [{"colA": "é"}]
     assert csvinput.sub_sheet_names == ["main"]
Example #6
0
 def test_csv_input_utf8(self, tmpdir):
     main = tmpdir.join('main.csv')
     main.write_text('colA\néαГ😼𝒞人', encoding='utf8')
     csvinput = CSVInput(input_name=tmpdir.strpath)  # defaults to utf8
     csvinput.read_sheets()
     assert list(csvinput.get_sheet_lines('main')) == \
         [{'colA': 'éαГ😼𝒞人'}]
     assert csvinput.sub_sheet_names == ['main']
Example #7
0
 def test_csv_no_directory(self):
     csvinput = CSVInput(input_name='nonesensedirectory')
     if sys.version > '3':
         with pytest.raises(FileNotFoundError):
             csvinput.read_sheets()
     else:
         with pytest.raises(OSError):
             csvinput.read_sheets()
Example #8
0
 def test_csv_input_latin1(self, tmpdir):
     main = tmpdir.join('main.csv')
     main.write_text('colA\né', encoding='latin-1')
     csvinput = CSVInput(input_name=tmpdir.strpath, main_sheet_name='main')
     csvinput.encoding = 'latin-1'
     csvinput.read_sheets()
     assert list(csvinput.get_main_sheet_lines()) == \
         [{'colA': 'é'}]
     assert csvinput.sub_sheet_names == []
 def test_csv_input_utf16(self, tmpdir):
     main = tmpdir.join('main.csv')
     main.write_text('colA\néαГ😼𝒞人', encoding='utf16')
     csvinput = CSVInput(input_name=tmpdir.strpath)
     csvinput.encoding = 'utf16'
     csvinput.read_sheets()
     assert list(csvinput.get_sheet_lines('main')) == \
         [{'colA': 'éαГ😼𝒞人'}]
     assert csvinput.sub_sheet_names == ['main']
Example #10
0
 def test_csv_input_latin1(self, tmpdir):
     main = tmpdir.join('main.csv')
     main.write_text('colA\né', encoding='latin-1')
     csvinput = CSVInput(input_name=tmpdir.strpath)
     csvinput.encoding = 'latin-1'
     csvinput.read_sheets()
     assert list(csvinput.get_sheet_lines('main')) == \
         [{'colA': 'é'}]
     assert csvinput.sub_sheet_names == ['main']
Example #11
0
 def test_csv_input_utf16(self, tmpdir):
     main = tmpdir.join('main.csv')
     main.write_text('colA\néαГ😼𝒞人', encoding='utf16')
     csvinput = CSVInput(input_name=tmpdir.strpath, main_sheet_name='main')
     csvinput.encoding = 'utf16'
     csvinput.read_sheets()
     assert list(csvinput.get_main_sheet_lines()) == \
         [{'colA': 'éαГ😼𝒞人'}]
     assert csvinput.sub_sheet_names == []
    def test_csv_input(self, tmpdir):
        main = tmpdir.join('main.csv')
        main.write('colA,colB\ncell1,cell2\ncell3,cell4')
        subsheet = tmpdir.join('subsheet.csv')
        subsheet.write('colC,colD\ncell5,cell6\ncell7,cell8')

        csvinput = CSVInput(input_name=tmpdir.strpath)

        csvinput.read_sheets()

        assert csvinput.sub_sheet_names == ['main', 'subsheet']
        assert list(csvinput.get_sheet_lines('main')) == \
            [{'colA': 'cell1', 'colB': 'cell2'}, {'colA': 'cell3', 'colB': 'cell4'}]
        assert list(csvinput.get_sheet_lines('subsheet')) == \
            [{'colC': 'cell5', 'colD': 'cell6'}, {'colC': 'cell7', 'colD': 'cell8'}]
Example #13
0
    def test_csv_input(self, tmpdir):
        main = tmpdir.join('main.csv')
        main.write('colA,colB\ncell1,cell2\ncell3,cell4')
        subsheet = tmpdir.join('subsheet.csv')
        subsheet.write('colC,colD\ncell5,cell6\ncell7,cell8')

        csvinput = CSVInput(input_name=tmpdir.strpath)

        csvinput.read_sheets()

        assert csvinput.sub_sheet_names == ['main', 'subsheet']
        assert list(csvinput.get_sheet_lines('main')) == \
            [{'colA': 'cell1', 'colB': 'cell2'}, {'colA': 'cell3', 'colB': 'cell4'}]
        assert list(csvinput.get_sheet_lines('subsheet')) == \
            [{'colC': 'cell5', 'colD': 'cell6'}, {'colC': 'cell7', 'colD': 'cell8'}]
Example #14
0
 def test_csv_no_files(self, tmpdir):
     csvinput = CSVInput(input_name=tmpdir.strpath, main_sheet_name='main')
     with pytest.raises(ValueError) as e:
         csvinput.read_sheets()
     assert 'Main sheet' in text_type(e) and 'not found' in text_type(e)
 def test_csv_no_directory(self):
     csvinput = CSVInput(input_name="nonesensedirectory")
     with pytest.raises(FileNotFoundError):
         csvinput.read_sheets()
Example #16
0
 def test_csv_no_files(self, tmpdir):
     csvinput = CSVInput(input_name=tmpdir.strpath, main_sheet_name='main')
     with pytest.raises(ValueError) as e:
         csvinput.read_sheets()
     assert 'Main sheet' in text_type(e) and 'not found' in text_type(e)