@@ -11,6 +11,21 @@ def test(param):
11
11
tests .append (param )
12
12
13
13
14
+ def resolve_relative_path (filename ):
15
+ """
16
+ Returns the full path to the filename provided, taken relative to the current file
17
+ e.g.
18
+ if this file was file.py at /path/to/file.py
19
+ and the provided relative filename was tests/unit.py
20
+ then the resulting path would be /path/to/tests/unit.py
21
+ """
22
+ r = __file__ .rsplit ("/" , 1 ) # poor man's os.path.dirname(__file__)
23
+ head = r [0 ]
24
+ if len (r ) == 1 or not head :
25
+ return filename
26
+ return "%s/%s" % (head , filename )
27
+
28
+
14
29
@test
15
30
def test_replace_defines_should_return_empty_line_given_empty_string ():
16
31
p = Preprocessor ()
@@ -204,7 +219,7 @@ def preprocess_should_replace_BIT_with_empty_string_unless_defined():
204
219
def test_process_include_file ():
205
220
p = Preprocessor ()
206
221
207
- defines = p .process_include_file ('fixtures/incl.h' )
222
+ defines = p .process_include_file (resolve_relative_path ( 'fixtures/incl.h' ) )
208
223
209
224
assert defines ['CONST1' ] == '42'
210
225
assert defines ['CONST2' ] == '99'
@@ -216,8 +231,8 @@ def test_process_include_file():
216
231
def test_process_include_file_with_multiple_files ():
217
232
p = Preprocessor ()
218
233
219
- defines = p .process_include_file ('fixtures/incl.h' )
220
- defines = p .process_include_file ('fixtures/incl2.h' )
234
+ defines = p .process_include_file (resolve_relative_path ( 'fixtures/incl.h' ) )
235
+ defines = p .process_include_file (resolve_relative_path ( 'fixtures/incl2.h' ) )
221
236
222
237
assert defines ['CONST1' ] == '42' , "constant from incl.h"
223
238
assert defines ['CONST2' ] == '123' , "constant overridden by incl2.h"
@@ -232,8 +247,8 @@ def test_process_include_file_using_database():
232
247
p = Preprocessor ()
233
248
p .use_db (db )
234
249
235
- p .process_include_file ('fixtures/incl.h' )
236
- p .process_include_file ('fixtures/incl2.h' )
250
+ p .process_include_file (resolve_relative_path ( 'fixtures/incl.h' ) )
251
+ p .process_include_file (resolve_relative_path ( 'fixtures/incl2.h' ) )
237
252
238
253
assert db ['CONST1' ] == '42' , "constant from incl.h"
239
254
assert db ['CONST2' ] == '123' , "constant overridden by incl2.h"
@@ -250,7 +265,7 @@ def test_process_include_file_should_not_load_database_keys_into_instance_define
250
265
p = Preprocessor ()
251
266
p .use_db (db )
252
267
253
- p .process_include_file ('fixtures/incl.h' )
268
+ p .process_include_file (resolve_relative_path ( 'fixtures/incl.h' ) )
254
269
255
270
# a bit hackish to reference instance-internal state
256
271
# but it's important to verify this, as we otherwise run out of memory on device
0 commit comments