Ejemplo n.º 1
0
def run(spec_files):
    for spec_file_name in spec_files:
        base_name = get_base_name(spec_file_name)

        print('\n**Testing ' + spec_file_name + '**\n')

        head, tail = os.path.split(base_name)

        if head:
            sys.path.append(os.path.join(os.getcwd(), head))

        processor = SpecificationProcessor(tail)

        with open(spec_file_name) as f:
            lines = f.readlines()

        spec_code = processor.process(lines)

        # http://docs.python.org/library/tempfile.html#tempfile.mktemp
        tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.py')
        tmp_file.write(spec_code)
        tmp_file.close()

        try:
            try:
                imp.load_source('spec', tmp_file.name)
            except SystemExit:
                print('Module ' + base_name + ' not found!')
        except Exception, e:
            os.unlink(tmp_file.name)
            sys.exit(str(e))

        os.unlink(tmp_file.name)
        os.unlink(tmp_file.name + 'c')
Ejemplo n.º 2
0
def run(spec_files):
    for spec_file_name in spec_files:
        base_name = get_base_name(spec_file_name)

        print('\n**Testing ' + spec_file_name + '**\n')

        head, tail = os.path.split(base_name)

        if head:
            sys.path.append(os.path.join(os.getcwd(), head))

        processor = SpecificationProcessor(tail)

        with open(spec_file_name) as f:
            lines = f.readlines()

        spec_code = processor.process(lines)

        # http://docs.python.org/library/tempfile.html#tempfile.mktemp
        tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.py')
        tmp_file.write(spec_code)
        tmp_file.close()

        try:
            try:
                imp.load_source('spec', tmp_file.name)
            except SystemExit:
                print('Module ' + base_name + ' not found!')
        except Exception, e:
            os.unlink(tmp_file.name)
            sys.exit(str(e))

        os.unlink(tmp_file.name)
        os.unlink(tmp_file.name + 'c')
Ejemplo n.º 3
0
def output_tests(option, opt, output_dir, parser):
    got_all = False

    for spec_name in get_specs():
        with open(spec_name) as f:
            lines = f.readlines()

        base_name = get_base_name(spec_name)
        processor = SpecificationProcessor(base_name)
        spec_code = processor.process(lines)

        if not os.path.exists(output_dir):
            os.makedirs(output_dir)

        py_file_name = 'test_' + base_name + '.py'
        py_file = os.path.join(output_dir, py_file_name)

        def write_file():
            print('Writing ' + py_file)

            with open(py_file, 'w') as f:
                f.write(spec_code)

        if os.path.exists(py_file):
            def do_nothing():
                print('Doing nothing.')

            possible_answers = {
                'Y': write_file,
                'N': do_nothing,
                'A': None
            }
            opts = '/'.join(possible_answers.keys())
            answer = None

            while answer not in possible_answers:
                if got_all:
                    answer = 'Y'
                else:
                    answer = raw_input(
                            'Are you sure you want to override file (' +
                            py_file_name + ')?\n' + opts + '\n')
                    answer = answer.upper()

                    if answer == 'A':
                        got_all = True
                        answer = 'Y'

            possible_answers[answer]()
        else:
            write_file()
Ejemplo n.º 4
0
def output_tests(option, opt, output_dir, parser):
    got_all = False

    for spec_name in get_specs():
        with open(spec_name) as f:
            lines = f.readlines()

        base_name = get_base_name(spec_name)
        processor = SpecificationProcessor(base_name)
        spec_code = processor.process(lines)

        if not os.path.exists(output_dir):
            os.makedirs(output_dir)

        py_file_name = 'test_' + base_name + '.py'
        py_file = os.path.join(output_dir, py_file_name)

        def write_file():
            print('Writing ' + py_file)

            with open(py_file, 'w') as f:
                f.write(spec_code)

        if os.path.exists(py_file):

            def do_nothing():
                print('Doing nothing.')

            possible_answers = {'Y': write_file, 'N': do_nothing, 'A': None}
            opts = '/'.join(possible_answers.keys())
            answer = None

            while answer not in possible_answers:
                if got_all:
                    answer = 'Y'
                else:
                    answer = raw_input(
                        'Are you sure you want to override file (' +
                        py_file_name + ')?\n' + opts + '\n')
                    answer = answer.upper()

                    if answer == 'A':
                        got_all = True
                        answer = 'Y'

            possible_answers[answer]()
        else:
            write_file()