-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
117 lines (94 loc) · 3.59 KB
/
test.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import unittest
import os
from main import TextProcessor
class TestProcessor(unittest.TestCase):
def setUp(self):
import os
self.BASE_PATH = os.path.dirname(os.path.abspath(__file__))
self.filepath = ""
# A variable to maintain at the end of each test
# files generated by them
self.maintain_files = False
def test_csv_read(self):
filepath = self.BASE_PATH + "/mockups/concessionario.csv"
processor = TextProcessor()
processor.read_csv(filepath)
print(processor.list_rows)
def test_csv_writter(self):
filepath = self.BASE_PATH + "/mockups/concessionario.csv"
processor = TextProcessor()
processor.read_csv(filepath)
self.filepath = self.BASE_PATH + "/mockups/nuovo_csv.csv"
processor.write_csv(self.filepath)
self.assertTrue(os.path.exists(self.filepath))
def test_json_reader(self):
filepath = self.BASE_PATH + "/mockups/concessionario.json"
processor = TextProcessor()
json_dict = processor.read_json(filepath)
self.assertIsNone(json_dict)
def test_json_writer(self):
self.filepath = self.BASE_PATH + "/mockups/nuovo_json.json"
processor = TextProcessor()
to_parse = {
'nome': 'Silvia',
"cognome": "Rossi",
"admin": False,
"mascote": 5,
"figli": {
"femmine": ["Clara", "Francesca"],
"maschi": []
}
}
processor.write_json(self.filepath, to_parse)
self.assertTrue(os.path.exists(self.filepath))
def test_json_datetime(self):
import datetime
self.filepath = self.BASE_PATH + "/mockups/nuovo_json.json"
processor = TextProcessor()
today = datetime.datetime.now()
to_parse = {
'nome': 'Silvia',
"cognome": "Rossi",
"admin": False,
"mascote": 5,
"figli": {
"femmine": ["Clara", "Francesca"],
"maschi": []
},
"creato": today
}
processor.write_json(self.filepath, to_parse)
self.assertTrue(os.path.exists(self.filepath))
def test_read_xml_categorie(self):
filepath = self.BASE_PATH + "/mockups/rai_feeds.xml"
processor = TextProcessor()
categorie = processor.read_xml_categorie(filepath)
print(categorie)
def test_read_xml_urls(self):
filepath = self.BASE_PATH + "/mockups/rai_feeds.xml"
processor = TextProcessor()
urls = processor.read_xml_urls(filepath)
print(urls)
def test_create_xml_by_csv(self):
filepath = self.BASE_PATH + "/mockups/concessionario.csv"
processor = TextProcessor()
processor.read_csv(filepath)
self.filepath = self.BASE_PATH + "/mockups/concessionario_full.xml"
processor.write_xml(self.filepath, processor.list_rows)
processor.pretty_print(self.filepath)
def test_beautify_xml(self):
filepath = self.BASE_PATH + "/mockups/rai_feeds.xml"
processor = TextProcessor()
processor.pretty_print(filepath)
def test_big_data(self):
""" Test con alcuni dati pressi da https://www.kaggle.com/
"""
filepath = self.BASE_PATH + "/mockups/complaints.csv"
processor = TextProcessor()
processor.read_csv(filepath)
print(
"Righe totali: {}".format(len(processor.list_rows))
)
def tearDown(self):
if os.path.exists(self.filepath) and not self.maintain_files:
os.unlink(self.filepath)