Failed to fetch fork details. Try again later.
-
Guillaume Blanchy authoredaec3e838
Forked from
reversaal / OhmPi
Source project has a limited visibility.
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# test_pamhyr.py -- Pamhyr
# Copyright (C) 2023-2024 INRAE
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# -*- coding: utf-8 -*-
import os
import unittest
import tempfile
from tools import flatten, parse_command_line
class FlattenTestCase(unittest.TestCase):
def test_flatten_0(self):
input = []
output = []
res = flatten(input)
self.assertEqual(len(res), len(output))
for i, o in enumerate(output):
self.assertEqual(res[i], o)
def test_flatten_1(self):
input = [['foo']]
output = ['foo']
res = flatten(input)
self.assertEqual(len(res), len(output))
for i, o in enumerate(output):
self.assertEqual(res[i], o)
def test_flatten_2(self):
input = [['foo', 'bar']]
output = ['foo', 'bar']
res = flatten(input)
self.assertEqual(len(res), len(output))
for i, o in enumerate(output):
self.assertEqual(res[i], o)
def test_flatten_3(self):
input = [['foo'], ['bar']]
output = ['foo', 'bar']
res = flatten(input)
self.assertEqual(len(res), len(output))
for i, o in enumerate(output):
self.assertEqual(res[i], o)
def test_flatten_4(self):
input = [['foo'], ['bar', 'baz'], ['bazz']]
output = ['foo', 'bar', 'baz', 'bazz']
res = flatten(input)
self.assertEqual(len(res), len(output))
for i, o in enumerate(output):
self.assertEqual(res[i], o)
def test_flatten_5(self):
input = [['foo'], ['bar', ['baz']], ['bazz']]
output = ['foo', 'bar', ['baz'], 'bazz']
res = flatten(input)
self.assertEqual(len(res), len(output))
for i, o in enumerate(output):
self.assertEqual(res[i], o)
class ToolsCMDParserTestCase(unittest.TestCase):
def test_trivial(self):
cmd = "foo"
expect = ["foo"]
res = parse_command_line(cmd)
self.assertEqual(len(res), len(expect))
for i, s in enumerate(res):
self.assertEqual(expect[i], s)
def test_unix_simple(self):
cmd = "/foo/bar a -b -c"
expect = ["/foo/bar", "a", '-b', "-c"]
res = parse_command_line(cmd)
self.assertEqual(len(res), len(expect))
for i, s in enumerate(res):
self.assertEqual(expect[i], s)
def test_unix_quoted(self):
cmd = "\"/foo/bar\" -a -b -c"
expect = ["/foo/bar", "-a", '-b', "-c"]
res = parse_command_line(cmd)
self.assertEqual(len(res), len(expect))
for i, s in enumerate(res):
self.assertEqual(expect[i], s)
def test_unix_quoted_with_space(self):
cmd = "\"/foo/bar baz\" -a -b -c"
expect = ["/foo/bar baz", "-a", '-b', "-c"]
res = parse_command_line(cmd)
self.assertEqual(len(res), len(expect))
for i, s in enumerate(res):
self.assertEqual(expect[i], s)
def test_unix_quoted_args(self):
cmd = "/foo/bar -a -b -c=\"baz\""
expect = ["/foo/bar", "-a", '-b', "-c=\"baz\""]
res = parse_command_line(cmd)
self.assertEqual(len(res), len(expect))
for i, s in enumerate(res):
self.assertEqual(expect[i], s)
def test_unix_quoted_args_with_space(self):
cmd = "/foo/bar -a -b -c=\"baz bazz\""
expect = ["/foo/bar", "-a", '-b', "-c=\"baz bazz\""]
res = parse_command_line(cmd)
self.assertEqual(len(res), len(expect))
for i, s in enumerate(res):
self.assertEqual(expect[i], s)
def test_unix_quoted2_args_with_space(self):
cmd = "\'/foo/bar baz\' -a -b -c='baz bazz'"
expect = ["/foo/bar baz", "-a", '-b', "-c='baz bazz'"]
res = parse_command_line(cmd)
self.assertEqual(len(res), len(expect))
for i, s in enumerate(res):
self.assertEqual(expect[i], s)
def test_unix_escape_space(self):
cmd = r"/foo/bar\ baz -a -b -c"
expect = [r"/foo/bar\ baz", "-a", '-b', "-c"]
res = parse_command_line(cmd)
self.assertEqual(len(res), len(expect))
for i, s in enumerate(res):
self.assertEqual(expect[i], s)
def test_windows_prog_files(self):
cmd = "\"C:\\Program Files (x86)\foo\bar\" a -b -c"
expect = ["C:\\Program Files (x86)\foo\bar", "a", '-b', "-c"]
res = parse_command_line(cmd)
self.assertEqual(len(res), len(expect))
for i, s in enumerate(res):
self.assertEqual(expect[i], s)
def test_windows_prog_files_args(self):
cmd = "\"C:\\Program Files (x86)\foo\bar\" a -b=\"baz bazz\" -c"
expect = [
"C:\\Program Files (x86)\foo\bar",
"a", '-b=\"baz bazz\"', "-c"
]
res = parse_command_line(cmd)
self.assertEqual(len(res), len(expect))
for i, s in enumerate(res):
self.assertEqual(expect[i], s)
# Parse must detect malformed command line... But is not :\
@unittest.expectedFailure
def test_wrong_format_0(self):
cmd = "'toto -a -b='baz bazz' -c"
expect = []
res = parse_command_line(cmd)
self.assertEqual(len(res), len(expect))
for i, s in enumerate(res):
self.assertEqual(expect[i], s)
@unittest.expectedFailure
def test_wrong_format_1(self):
cmd = "\"toto -a -b=\"baz bazz\" -c"
expect = []
res = parse_command_line(cmd)
self.assertEqual(len(res), len(expect))
for i, s in enumerate(res):
self.assertEqual(expect[i], s)
@unittest.expectedFailure
def test_wrong_format_2(self):
cmd = "'toto -a -b=\"baz bazz\" -c"
expect = []
res = parse_command_line(cmd)
self.assertEqual(len(res), len(expect))
for i, s in enumerate(res):
self.assertEqual(expect[i], s)