Example #1
0
def read_function_registry(filename):
  f = open(filename)
  lines = f.readlines()
  f.close()
  new_format = [l for l in lines if not l.startswith('#') and l.find(',') > -1]
  function_registry = {}
  for line in lines:
    line = line.strip()
    if not line:
      continue
    if line.startswith('#'):
      continue
    if new_format:
      alias, rest = line.split('=')
      decorators = rest.split(',')
      fq_name = decorators.pop(0).strip()
      function_registry[alias.strip()] = fq_name, decorators
    else:
      alias, fq_name = line.split('=')
      fq_name = fq_name.strip()
      try:
        method = runtime.import_module_symbol(fq_name)
      except ImportError:
        logging.warning('unable to import function registry symbol %s', fq_name)
        method = None
      function_registry[alias.strip()] = fq_name, method
  return new_format, function_registry
Example #2
0
def read_function_registry(filename):
  f = open(filename)
  lines = f.readlines()
  f.close()
  new_format = [ l for l in lines if not l.startswith('#') and l.find(',') > -1]
  function_registry = {}
  for line in lines:
    line = line.strip()
    if not line:
      continue
    if line.startswith('#'):
      continue
    if new_format:
      alias, rest = line.split('=')
      decorators = rest.split(',')
      fq_name = decorators.pop(0).strip()
      function_registry[alias.strip()] = fq_name, decorators
    else:
      alias, fq_name = line.split('=')
      fq_name = fq_name.strip()
      try:
        method = runtime.import_module_symbol(fq_name)
      except ImportError:
        logging.warning('unable to import function registry symbol %s', fq_name)
        method = None
      function_registry[alias.strip()] = fq_name, method
  return new_format, function_registry
Example #3
0
def read_function_registry(filename):
  f = open(filename)
  function_registry = {}
  try:
    for line in f:
      line = line.strip()
      if not line:
        continue
      if line.startswith('#'):
        continue
      
      alias, fq_name = line.split('=')
      fq_name = fq_name.strip()
      try:
        method = runtime.import_module_symbol(fq_name)
      except ImportError:
        logging.warning('unable to import function registry symbol %s', fq_name)
        method = None
                        
      function_registry[alias.strip()] = fq_name, method
    return function_registry
  finally:
    f.close()
Example #4
0
    def process_file(self, filename):
        buffer = StringIO.StringIO()
        reset_sys_modules()

        classname = util.filename2classname(filename)
        modulename = util.filename2modulename(filename)
        test_output_path = os.path.join(self.options.test_output,
                                        classname + '.txt')

        if self.options.verbose:
            sys.stderr.write(modulename + ' ... ')

        compile_failed = False
        if self.options.debug or self.options.compile:
            try:
                self.compiler.compile_file(filename)
            except Exception as e:
                compile_failed = True
                print >> buffer, '=' * 70
                print >> buffer, 'FAIL:', modulename, '(' + filename + ')'
                print >> buffer, '-' * 70
                traceback.print_exc(None, buffer)
            if self.options.debug:
                if 'parse_tree' in self.options.debug_flags:
                    print >> buffer, "parse_tree:"
                    visitor.print_tree(self.compiler._parse_tree, output=buffer)
                if 'analyzed_tree' in self.options.debug_flags:
                    print >> buffer, "analyzed_tree:"
                    visitor.print_tree(self.compiler._analyzed_tree,
                                       output=buffer)
                if 'optimized_tree' in self.options.debug_flags:
                    print >> buffer, "optimized_tree:"
                    visitor.print_tree(self.compiler._optimized_tree,
                                       output=buffer)
                if 'hoisted_tree' in self.options.debug_flags:
                    print >> buffer, "hoisted_tree:"
                    visitor.print_tree(self.compiler._hoisted_tree,
                                       output=buffer)
                if 'source_code' in self.options.debug_flags:
                    print >> buffer, "source_code:"
                    for i, line in enumerate(self.compiler._source_code.split(
                            '\n')):
                        print >> buffer, '% 3s' % (i + 1), line

        test_failed = False
        if not self.options.skip_test:
            import tests

            current_output = None
            raised_exception = False
            try:
                if self.options.debug or self.options.compile:
                    template_module = util.load_module_from_src(
                        self.compiler._source_code, filename, modulename)
                else:
                    template_module = runtime.import_module_symbol(modulename)
            except Exception as e:
                # An exception here means the template is unavailble; the test
                # fails.
                test_failed = True
                raised_exception = True
                current_output = str(e)

            if not test_failed:
                try:
                    template_class = getattr(template_module, classname)
                    template = template_class(search_list=self.search_list)
                    current_output = template.main().encode('utf8')
                except Exception as e:
                    # An exception here doesn't meant that the test fails
                    # necessarily since libraries don't have a class; as long as
                    # the expected output matches the exception, the test
                    # passes.
                    raised_exception = True
                    current_output = str(e)

            if not test_failed:
                if self.options.test_accept_result:
                    test_file = open(test_output_path, 'w')
                    test_file.write(current_output)
                    test_file.close()
                try:
                    test_file = open(test_output_path)
                except IOError as e:
                    # An excpetion here means that the expected output is
                    # unavailbe; the test fails.
                    test_failed = True
                    raised_exception = True
                    current_output = str(e)

            if test_failed:
                test_output = None
            else:
                test_output = test_file.read()
                if current_output != test_output:
                    test_failed = True
                    if self.options.debug:
                        print >> buffer, "expected output:"
                        print >> buffer, test_output
                        print >> buffer, "actual output:"
                        print >> buffer, current_output

            if compile_failed or test_failed:
                self.num_tests_failed += 1
                if self.options.verbose:
                    sys.stderr.write('FAIL\n')
                else:
                    sys.stderr.write('F')
                current_output_path = os.path.join(self.options.test_output,
                                                   classname + '.failed')
                f = open(current_output_path, 'w')
                f.write(current_output)
                f.close()
                print >> buffer, '=' * 70
                print >> buffer, 'FAIL:', modulename, '(' + filename + ')'
                print >> buffer, '-' * 70
                print >> buffer, 'Compare expected and actual output with:'
                print >> buffer, ' '.join('    diff -u', test_output_path,
                                          current_output_path)
                print >> buffer, 'Show debug information for the test with:'
                test_cmd = [arg for arg in sys.argv if arg not in self.files]
                if '--debug' not in test_cmd:
                    test_cmd.append('--debug')
                test_cmd = ' '.join(test_cmd)
                print >> buffer, '   ', test_cmd, filename
                if raised_exception:
                    print >> buffer, '-' * 70
                    print >> buffer, current_output
                    traceback.print_exc(None, buffer)
                print >> buffer
                self.buffer.write(buffer.getvalue())
            else:
                if self.options.verbose:
                    sys.stderr.write('ok\n')
                else:
                    sys.stderr.write('.')
            self.num_tests_run += 1