Skip to content

Commit a5583b7

Browse files
committed
[fix] add tests
1 parent 3e896b0 commit a5583b7

File tree

6 files changed

+90
-44
lines changed

6 files changed

+90
-44
lines changed

commit.sh

100644100755
File mode changed.

log.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
# Logs
22

3-
- 08/12 - Add option to pass a `list` as `schema`
3+
- 2022-02-11 : Add docs
4+
- 2022-01-20 :
5+
- first release : `https://pypi.org/project/csv-to-custom-json`
6+
- note : [https://packaging.python.org/en/latest/tutorials/packaging-projects/](https://packaging.python.org/en/latest/tutorials/packaging-projects/)
7+
- note : `python3 -m twine upload dist/*`
8+
- 2021-12-08 : Add option to pass a `list` as `schema`

tests/test_callBack.py

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

tests/test_callBack_force.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
class Test(unittest.TestCase):
7-
def test_callBack_force(self):
7+
def test_callBack_force_2(self):
88
def function1(values):
99
return None
1010

@@ -15,23 +15,11 @@ def function2(useless, useless2):
1515
"num2": function1,
1616
"num3": "string"
1717
}, {
18-
"lineCallBack": function2,
19-
"debug": True
18+
"callBackForce": True,
19+
"lineCallBack": function2
2020
})
2121
self.assertEqual(test, [
22-
{
23-
"num1": "1",
24-
"num2": None,
25-
"num3": "3"
26-
},
27-
{
28-
"num1": "4",
29-
"num2": None,
30-
"num3": "6"
31-
},
32-
{
33-
"num1": "7",
34-
"num2": None,
35-
"num3": "9"
36-
}
22+
None,
23+
None,
24+
None
3725
])

tests/test_callBack_force_2.py

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

tests/test_callBack_value.py

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

0 commit comments

Comments
 (0)