Skip to content

Commit 2c3fa7c

Browse files
committed
[feature] add tests
1 parent d69114b commit 2c3fa7c

30 files changed

+1563
-657
lines changed

tests/test.py

Lines changed: 0 additions & 657 deletions
This file was deleted.

tests/test_array_parse.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import unittest
2+
3+
from src.csv_to_custom_json.csv_to_custom_json import parseFile
4+
5+
class Test(unittest.TestCase):
6+
def test_array_parse(self):
7+
def function1(allValues):
8+
mystring = 'toto{}'.format(','.join(map(str, allValues)))
9+
return mystring
10+
def function2(uselessArg):
11+
return "arrow"
12+
test = parseFile("./tests/simple_complexe.csv", [
13+
"num4",
14+
"text",
15+
function1,
16+
function2
17+
], {
18+
"arrayParse": False
19+
})
20+
self.assertEqual(test, [
21+
[
22+
"num4",
23+
"text",
24+
"toto1,2,3,4",
25+
"arrow"
26+
],
27+
[
28+
"num4",
29+
"text",
30+
"toto4,5,6,7",
31+
"arrow"
32+
],
33+
[
34+
"num4",
35+
"text",
36+
"toto7,8,9,10",
37+
"arrow"
38+
]
39+
])

tests/test_avoidVoidLine.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import unittest
2+
3+
from src.csv_to_custom_json.csv_to_custom_json import parseFile
4+
5+
class Test(unittest.TestCase):
6+
def test_array_parse(self):
7+
def function1(allValues):
8+
mystring = 'toto{}'.format(','.join(map(str, allValues)))
9+
return mystring
10+
def function2(uselessArg):
11+
return "arrow"
12+
test = parseFile("./tests/simple_complexe_with_void_line.csv", [
13+
"num4",
14+
"text",
15+
[
16+
"arrayHereLol",
17+
[
18+
"andHereLol",
19+
{
20+
"obj": "lol",
21+
"num4": "int"
22+
}
23+
]
24+
],
25+
function1,
26+
function2,
27+
{
28+
"staticValue": "value",
29+
"num1": "int"
30+
}
31+
], {
32+
"avoidVoidLine": True
33+
})
34+
self.assertEqual(test, [
35+
[
36+
"4",
37+
"text",
38+
[
39+
"arrayHereLol",
40+
[
41+
"andHereLol",
42+
{
43+
"obj": "lol",
44+
"num4": 4
45+
}
46+
]
47+
],
48+
"toto1,2,3,4",
49+
"arrow",
50+
{
51+
"staticValue": "value",
52+
"num1": 1
53+
}
54+
],
55+
[
56+
"7",
57+
"text",
58+
[
59+
"arrayHereLol",
60+
[
61+
"andHereLol",
62+
{
63+
"obj": "lol",
64+
"num4": 7
65+
}
66+
]
67+
],
68+
"toto4,5,6,7",
69+
"arrow",
70+
{
71+
"staticValue": "value",
72+
"num1": 4
73+
}
74+
],
75+
[
76+
"10",
77+
"text",
78+
[
79+
"arrayHereLol",
80+
[
81+
"andHereLol",
82+
{
83+
"obj": "lol",
84+
"num4": 10
85+
}
86+
]
87+
],
88+
"toto7,8,9,10",
89+
"arrow",
90+
{
91+
"staticValue": "value",
92+
"num1": 7
93+
}
94+
]
95+
])

tests/test_avoidVoidLine2.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import unittest
2+
3+
from src.csv_to_custom_json.csv_to_custom_json import parseFile
4+
5+
class Test(unittest.TestCase):
6+
def test_array_parse(self):
7+
def function1(allValues):
8+
mystring = 'toto{}'.format(','.join(map(str, allValues)))
9+
return mystring
10+
def function2(uselessArg):
11+
return "arrow"
12+
test = parseFile("./tests/simple_complexe_with_void_line.csv", [
13+
"num4",
14+
"text",
15+
[
16+
"arrayHereLol",
17+
[
18+
"andHereLol",
19+
{
20+
"obj": "lol",
21+
"num4": "int"
22+
}
23+
]
24+
],
25+
function1,
26+
function2,
27+
{
28+
"staticValue": "value",
29+
"num1": "int"
30+
}
31+
])
32+
self.assertEqual(test, [
33+
[
34+
"4",
35+
"text",
36+
[
37+
"arrayHereLol",
38+
[
39+
"andHereLol",
40+
{
41+
"obj": "lol",
42+
"num4": 4
43+
}
44+
]
45+
],
46+
"toto1,2,3,4",
47+
"arrow",
48+
{
49+
"staticValue": "value",
50+
"num1": 1
51+
}
52+
],
53+
[
54+
"7",
55+
"text",
56+
[
57+
"arrayHereLol",
58+
[
59+
"andHereLol",
60+
{
61+
"obj": "lol",
62+
"num4": 7
63+
}
64+
]
65+
],
66+
"toto4,5,6,7",
67+
"arrow",
68+
{
69+
"staticValue": "value",
70+
"num1": 4
71+
}
72+
],
73+
[
74+
None,
75+
"text",
76+
[
77+
"arrayHereLol",
78+
[
79+
"andHereLol",
80+
{
81+
"obj": "lol",
82+
"num4": None
83+
}
84+
]
85+
],
86+
"toto",
87+
"arrow",
88+
{
89+
"staticValue": "value",
90+
"num1": ""
91+
}
92+
],
93+
[
94+
"10",
95+
"text",
96+
[
97+
"arrayHereLol",
98+
[
99+
"andHereLol",
100+
{
101+
"obj": "lol",
102+
"num4": 10
103+
}
104+
]
105+
],
106+
"toto7,8,9,10",
107+
"arrow",
108+
{
109+
"staticValue": "value",
110+
"num1": 7
111+
}
112+
]
113+
])

tests/test_avoidVoidLine3.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import unittest
2+
3+
from src.csv_to_custom_json.csv_to_custom_json import parseFile
4+
5+
class Test(unittest.TestCase):
6+
def test_array_parse(self):
7+
def function1(allValues):
8+
mystring = 'toto{}'.format(','.join(map(str, allValues)))
9+
return mystring
10+
def function2(uselessArg):
11+
return "arrow"
12+
test = parseFile([
13+
"num1,num2,num3,num4",
14+
"1,2,3,4",
15+
"4,5,6,7",
16+
"",
17+
"7,8,9,10"
18+
], [
19+
"num4",
20+
"text",
21+
[
22+
"arrayHereLol",
23+
[
24+
"andHereLol",
25+
{
26+
"obj": "lol",
27+
"num4": "int"
28+
}
29+
]
30+
],
31+
function1,
32+
function2,
33+
{
34+
"staticValue": "value",
35+
"num1": "int"
36+
}
37+
], {
38+
"avoidVoidLine": True
39+
})
40+
self.assertEqual(test, [
41+
[
42+
"4",
43+
"text",
44+
[
45+
"arrayHereLol",
46+
[
47+
"andHereLol",
48+
{
49+
"obj": "lol",
50+
"num4": 4
51+
}
52+
]
53+
],
54+
"toto1,2,3,4",
55+
"arrow",
56+
{
57+
"staticValue": "value",
58+
"num1": 1
59+
}
60+
],
61+
[
62+
"7",
63+
"text",
64+
[
65+
"arrayHereLol",
66+
[
67+
"andHereLol",
68+
{
69+
"obj": "lol",
70+
"num4": 7
71+
}
72+
]
73+
],
74+
"toto4,5,6,7",
75+
"arrow",
76+
{
77+
"staticValue": "value",
78+
"num1": 4
79+
}
80+
],
81+
[
82+
"10",
83+
"text",
84+
[
85+
"arrayHereLol",
86+
[
87+
"andHereLol",
88+
{
89+
"obj": "lol",
90+
"num4": 10
91+
}
92+
]
93+
],
94+
"toto7,8,9,10",
95+
"arrow",
96+
{
97+
"staticValue": "value",
98+
"num1": 7
99+
}
100+
]
101+
])

tests/test_callBack_force.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import unittest
2+
3+
from src.csv_to_custom_json.csv_to_custom_json import parseFile
4+
5+
class Test(unittest.TestCase):
6+
def test_callBack_force(self):
7+
def function1(values):
8+
return None
9+
def function2(useless, useless2):
10+
return None
11+
test = parseFile("./tests/simple.csv", {
12+
"num1": "string",
13+
"num2": function1,
14+
"num3": "string"
15+
}, {
16+
"lineCallBack": function2,
17+
"debug": True
18+
})
19+
self.assertEqual(test, [
20+
{
21+
"num1": "1",
22+
"num2": None,
23+
"num3": "3"
24+
},
25+
{
26+
"num1": "4",
27+
"num2": None,
28+
"num3": "6"
29+
},
30+
{
31+
"num1": "7",
32+
"num2": None,
33+
"num3": "9"
34+
}
35+
])

0 commit comments

Comments
 (0)