forked from PinguinoIDE/pinguino-ide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
113 lines (83 loc) · 3.05 KB
/
tests.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
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import unittest
import os
import sys
NAME = "Pinguino IDE"
VERSION = "11.0"
SUBVERSION = "beta.1"
os.environ["NAME"] = NAME
os.environ["VERSION"] = VERSION
os.environ["SUBVERSION"] = SUBVERSION
os.environ["PINGUINO_HOME"] = os.path.abspath(sys.path[0])
# For PyInstaller compatibility
if os.path.exists(os.path.abspath("pinguino_data")):
os.environ["PINGUINO_DATA"] = os.path.abspath("pinguino_data")
else:
os.environ["PINGUINO_DATA"] = os.getenv("PINGUINO_HOME")
sys.path.append(os.path.join(os.getenv("PINGUINO_DATA"), "qtgui", "resources"))
from qtgui.pinguino_api.pinguino import Pinguino
from qtgui.pinguino_api.pinguino_config import PinguinoConfig
from qtgui.ide.methods.config import Config
Pinguino = Pinguino()
PinguinoConfig.set_environ_vars()
PinguinoConfig.check_user_files()
config = Config()
PinguinoConfig.update_pinguino_paths(config, Pinguino)
PinguinoConfig.update_pinguino_extra_options(config, Pinguino)
PinguinoConfig.update_user_libs(Pinguino)
########################################################################
class TestPinguinoIDE(unittest.TestCase):
""""""
#----------------------------------------------------------------------
def test_delete_comments(self):
cases = (
("//Pinguino Rules!", ""),
("/*Pinguino Rules!*/", ""),
("/*Pinguino //Rules!*/", ""),
("///*Pinguino Rules!*/", ""),
([
"#define LED1 0\n",
"//#define LED2 1\n",
"/*\n",
"1\n",
"2\n",
"3\n",
"*/\n",
"#include <math.h>\n",
],[
"#define LED1 0\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"#include <math.h>\n",
]),
)
for case in cases:
got = Pinguino.remove_comments(case[0])
expected = case[1]
self.assertEqual(got, expected,
"Remove comments: Failure\ngot: '%s'\nexpected: '%s'"%(got, expected))
#----------------------------------------------------------------------
def test_preprocess(self):
regobject, libinstructions = Pinguino.get_regobject_libinstructions(8)
for line, expected, include, define in libinstructions:
got = Pinguino.replace_word(line+"()", regobject, libinstructions)
self.assertEqual(got, expected+"()",
"Preprocess: Failure\ngot: '%s'\nexpected: '%s'"%(got, expected))
#Test extra words
cases = (
("pinMode", "pinmode"),
("CDC.read", "CDCgets"),
("GLCD.init", "Init"),
)
for line, expected, in cases:
got = Pinguino.replace_word(line+"()", regobject, libinstructions)
expected += "()"
self.assertEqual(got, expected,
"Preprocess: Failure\ngot: '%s'\nexpected: '%s'"%(got, expected))
if __name__ == "__main__":
unittest.main()