forked from wireservice/csvkit
/
test_convert.py
31 lines (22 loc) · 1.03 KB
/
test_convert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import unittest
from csvkit import convert
class TestConvert(unittest.TestCase):
def test_valid_file(self):
with open('examples/test.xls', 'r') as f:
output = convert.convert(f, 'xls')
with open('examples/testxls_converted.csv', 'r') as f:
self.assertEquals(f.read(), output)
def test_no_file(self):
self.assertRaises(ValueError, convert.convert, None, 'xls')
def test_no_format(self):
with open('examples/dummy.csv', 'r') as f:
self.assertRaises(ValueError, convert.convert, f, None)
def test_invalid_format(self):
with open('examples/dummy.csv', 'r') as f:
self.assertRaises(ValueError, convert.convert, f, 'INVALID')
def test_guess_fixed(self):
self.assertEqual('fixed', convert.guess_format('testdata'))
def test_guess_xls(self):
self.assertEqual('xls', convert.guess_format('testdata.xls'))
def test_guess_csv(self):
self.assertEqual('csv', convert.guess_format('testdata.csv'))