forked from coala/coala-bears
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSVLintBearTest.py
63 lines (53 loc) · 2.73 KB
/
CSVLintBearTest.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import unittest
from queue import Queue
from bears.csv.CSVLintBear import CSVLintBear
from coalib.testing.BearTestHelper import generate_skip_decorator
from coalib.testing.LocalBearTestHelper import verify_local_bear, execute_bear
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY
from coalib.settings.Section import Section
from coala_utils.ContextManagers import prepare_file
good_file = """id,first_name,last_name,email,gender,ip_address
1,Cynthia,Rogers,[email protected],Female,158.131.39.207
2,Lisa,Carroll,[email protected],Female,157.69.195.53
3,Kevin,Baker,[email protected],Male,113.189.69.4
"""
major_file = """id,first_name,last_name,email,gender,ip_address
1,Cynthia,Rogers,[email protected],Female,158.131.39.207
2,Lisa,Carroll,[email protected],157.69.195.53
3,Kevin,Baker,[email protected],Male,113.189.69.4
"""
normal_file = """id,first_name,last_name,email,gender,ip_address,first_name
1,Cynthia,Rogers,[email protected],Female,158.131.39.207,A
2,Lisa,Carroll,[email protected],Female,157.69.195.53,A
3,Kevin,Baker,[email protected],Male,113.189.69.4,A
"""
CSVLintBearTest = verify_local_bear(CSVLintBear,
valid_files=(good_file,),
invalid_files=(major_file, normal_file))
@generate_skip_decorator(CSVLintBear)
class CSVLintBearSeverityTest(unittest.TestCase):
def setUp(self):
self.section = Section('')
self.uut = CSVLintBear(self.section, Queue())
def test_normal(self):
content = normal_file.splitlines()
with prepare_file(content, None) as (file, fname):
with execute_bear(self.uut, fname, file) as results:
self.assertEqual(results[0].severity, RESULT_SEVERITY.NORMAL)
self.assertEqual(results[0].message,
'A column in the CSV header'
' has a duplicate name. Column: 7')
self.assertEqual(results[0].origin,
'CSVLintBear (duplicate_column_name)')
self.assertEqual(results[0].aspect, None)
def test_errors(self):
content = major_file.splitlines()
with prepare_file(content, None) as (file, fname):
with execute_bear(self.uut, fname, file) as results:
self.assertEqual(results[0].severity, RESULT_SEVERITY.MAJOR)
self.assertEqual(results[0].message,
'Row has a different number of columns.'
' (than the first row in the file)')
self.assertEqual(results[0].origin,
'CSVLintBear (ragged_rows)')
self.assertEqual(results[0].aspect, None)