296
296
test_doc = test_doc_file.read()
298
298
test_doc_file.close()
299
if doctests is not None:
300
test_doc = test_doc.replace('special = {}', get_special(doctests))
299
301
test_doc_path = os.path.join(dir_path, file_name)
300
302
if os.path.isfile(test_doc_path):
301
303
# This harness was made in a previous run.
309
311
bzr_add([test_doc_path])
314
def get_special(doctests):
315
"""extract the special setups from test_system_documentation."""
316
system_doc_lines = []
318
doctest_pattern = re.compile(r"^ '(%s)[^']*':" % '|'.join(doctests))
319
system_doc_path = os.path.join(
320
OLD_TOP, 'ftests', 'test_system_documentation.py')
321
system_doc = open(system_doc_path)
324
for line in system_doc:
325
match = doctest_pattern.match(line)
326
if match is not None:
328
print ' * Extracting special test for %s' % match.group(1)
330
special_lines.append(line.replace(' ', ' '))
332
system_doc_lines.append(line)
333
if in_special and '),' in line:
337
if len(special_lines) == 0:
338
# There was nothing to extract.
339
return 'special = {}'
340
# Get the setup and teardown functions.
341
special_lines.insert(0, 'special = {\n')
342
special_lines.append(' }')
343
code = ''.join(special_lines)
344
helper_pattern = re.compile(r'\b(setUp|tearDown)=(\w*)\b')
345
helpers = set(match.group(2) for match in helper_pattern.finditer(code))
346
if 'setUp' in helpers:
347
helpers.remove('setUp')
348
if 'tearDown' in helpers:
349
helpers.remove('tearDown')
350
# Extract the setup and teardown functions.
351
lines = list(system_doc_lines)
352
system_doc_lines = []
354
helper_pattern = re.compile(r'^def (%s)\b' % '|'.join(helpers))
357
if in_helper and len(line) > 1 and line[0] != ' ':
359
match = helper_pattern.match(line)
360
if match is not None:
362
print ' * Extracting special function for %s' % match.group(1)
364
helper_lines.append(line)
366
system_doc_lines.append(line)
367
if len(helper_lines) > 0:
368
code = ''.join(helper_lines) + code
369
# Write the smaller test_system_documentation.py.
370
system_doc = open(system_doc_path, 'w')
372
system_doc.write(''.join(system_doc_lines))
375
# Return the local app's specials code.
376
special_lines.insert(0, 'special = {\n')
377
special_lines.append(' }')
312
381
def handle_py_file(old_path, new_path, subdir):
313
382
"""Migrate python files."""
314
383
if subdir in APP_DIRECTORIES: