~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to utilities/migrater/migrater.py

  • Committer: Curtis Hovey
  • Date: 2011-12-24 05:07:46 UTC
  • mto: This revision was merged to the branch mainline in revision 14599.
  • Revision ID: curtis.hovey@canonical.com-20111224050746-uh4llh71lr73f61e
Removed unneeded test; ./doc is gone.

Show diffs side-by-side

added added

removed removed

Lines of Context:
296
296
        test_doc = test_doc_file.read()
297
297
    finally:
298
298
        test_doc_file.close()
299
 
    if doctests is not None:
300
 
        test_doc = test_doc.replace('special = {}', get_special(doctests))
301
299
    test_doc_path = os.path.join(dir_path, file_name)
302
300
    if os.path.isfile(test_doc_path):
303
301
        # This harness was made in a previous run.
311
309
    bzr_add([test_doc_path])
312
310
 
313
311
 
314
 
def get_special(doctests):
315
 
    """extract the special setups from test_system_documentation."""
316
 
    system_doc_lines = []
317
 
    special_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)
322
 
    try:
323
 
        in_special = False
324
 
        for line in system_doc:
325
 
            match = doctest_pattern.match(line)
326
 
            if match is not None:
327
 
                in_special = True
328
 
                print '    * Extracting special test for %s' % match.group(1)
329
 
            if in_special:
330
 
                special_lines.append(line.replace('        ', '    '))
331
 
            else:
332
 
                system_doc_lines.append(line)
333
 
            if in_special and '),' in line:
334
 
                in_special = False
335
 
    finally:
336
 
        system_doc.close()
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 = []
353
 
    helper_lines = []
354
 
    helper_pattern = re.compile(r'^def (%s)\b' % '|'.join(helpers))
355
 
    in_helper = False
356
 
    for line in lines:
357
 
        if in_helper and len(line) > 1 and line[0] != ' ':
358
 
            in_helper = False
359
 
        match = helper_pattern.match(line)
360
 
        if match is not None:
361
 
            in_helper = True
362
 
            print '    * Extracting special function for %s' % match.group(1)
363
 
        if in_helper:
364
 
            helper_lines.append(line)
365
 
        else:
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')
371
 
    try:
372
 
        system_doc.write(''.join(system_doc_lines))
373
 
    finally:
374
 
        system_doc.close()
375
 
    # Return the local app's specials code.
376
 
    special_lines.insert(0, 'special = {\n')
377
 
    special_lines.append('    }')
378
 
    return code
379
 
 
380
 
 
381
312
def handle_py_file(old_path, new_path, subdir):
382
313
    """Migrate python files."""
383
314
    if subdir in APP_DIRECTORIES: