Skip to content

Commit c8b3537

Browse files
theotherjimmyadbridge
authored andcommitted
Assert that reduce depth works and parameterize over path sep
1 parent 3bc1928 commit c8b3537

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

tools/test/memap/memap_test.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import pytest
2222

23+
import tools.memap
2324
from tools.memap import MemapParser
2425
from copy import deepcopy
2526

@@ -137,7 +138,7 @@ def memap_parser():
137138
return memap_parser
138139

139140

140-
def generate_test_helper(memap_parser, format, depth, file_output=None):
141+
def generate_test_helper(memap_parser, format, depth, sep, file_output=None):
141142
"""
142143
Helper that tests that the member variables "modules" is
143144
unchanged after calling "generate_output"
@@ -147,57 +148,64 @@ def generate_test_helper(memap_parser, format, depth, file_output=None):
147148
:param format: the file type to output
148149
:param file_output: the file to output to
149150
"""
150-
151151
old_modules = deepcopy(memap_parser.modules)
152152

153+
tools.memap.sep = sep
153154
memap_parser.generate_output(format, depth, file_output=file_output)
154155

155156
assert memap_parser.modules == old_modules,\
156157
"generate_output modified the 'modules' property"
157158

159+
for file_name in memap_parser.short_modules:
160+
assert(len(file_name.split(tools.memap.sep)) <= depth)
161+
158162

159163
@pytest.mark.parametrize("depth", [1, 2, 20])
160-
def test_report_computed(memap_parser, depth):
164+
@pytest.mark.parametrize("sep", ["\\", "/"])
165+
def test_report_computed(memap_parser, depth, sep):
161166
"""
162167
Test that a report and summary are computed
163168
164169
:param memap_parser: Mocked parser
165170
:param depth: the detail of the output
166171
"""
167172

168-
memap_parser.generate_output('table', depth)
173+
memap_parser.generate_output('table', depth, sep)
169174

170175
# Report is created after generating output
171176
assert memap_parser.mem_summary
172177
assert memap_parser.mem_report
173178

174179

175180
@pytest.mark.parametrize("depth", [1, 2, 20])
176-
def test_generate_output_table(memap_parser, depth):
181+
@pytest.mark.parametrize("sep", ["\\", "/"])
182+
def test_generate_output_table(memap_parser, depth, sep):
177183
"""
178184
Test that an output of type "table" can be generated correctly
179185
:param memap_parser: Mocked parser
180186
:param depth: the detail of the output
181187
"""
182-
generate_test_helper(memap_parser, 'table', depth)
188+
generate_test_helper(memap_parser, 'table', depth, sep)
183189

184190

185191
@pytest.mark.parametrize("depth", [1, 2, 20])
186-
def test_generate_output_json(memap_parser, tmpdir, depth):
192+
@pytest.mark.parametrize("sep", ["\\", "/"])
193+
def test_generate_output_json(memap_parser, tmpdir, depth, sep):
187194
"""
188195
Test that an output of type "json" can be generated correctly
189196
:param memap_parser: Mocked parser
190197
:param tmpdir: a unique location to place an output file
191198
:param depth: the detail of the output
192199
"""
193200
file_name = str(tmpdir.join('output.json').realpath())
194-
generate_test_helper(memap_parser, 'json', depth, file_name)
201+
generate_test_helper(memap_parser, 'json', depth, sep, file_name)
195202
assert isfile(file_name), "Failed to create json file"
196203
json.load(open(file_name))
197204

198205

199206
@pytest.mark.parametrize("depth", [1, 2, 20])
200-
def test_generate_output_csv_ci(memap_parser, tmpdir, depth):
207+
@pytest.mark.parametrize("sep", ["\\", "/"])
208+
def test_generate_output_csv_ci(memap_parser, tmpdir, depth, sep):
201209
"""
202210
Test ensures that an output of type "csv-ci" can be generated correctly
203211
@@ -206,5 +214,5 @@ def test_generate_output_csv_ci(memap_parser, tmpdir, depth):
206214
:param depth: the detail of the output
207215
"""
208216
file_name = str(tmpdir.join('output.csv').realpath())
209-
generate_test_helper(memap_parser, 'csv-ci', depth, file_name)
217+
generate_test_helper(memap_parser, 'csv-ci', depth, sep, file_name)
210218
assert isfile(file_name), "Failed to create csv-ci file"

0 commit comments

Comments
 (0)