Ejemplo n.º 1
0
 def Check(self,
           code,
           pythonpath=(),
           skip_repeat_calls=True,
           report_errors=True,
           filename=None,
           quick=False,
           imports_map=None,
           **kwargs):
     """Run an inference smoke test for the given code."""
     self.ConfigureOptions(skip_repeat_calls=skip_repeat_calls,
                           quick=quick,
                           **self._GetPythonpathArgs(
                               pythonpath, imports_map))
     try:
         src = _Format(code)
         errorlog = test_utils.TestErrorLog(code)
         if errorlog.expected:
             self.fail(
                 "Cannot assert errors with Check(); use CheckWithErrors()")
         analyze.check_types(src,
                             filename,
                             loader=self.loader,
                             errorlog=errorlog,
                             options=self.options,
                             **kwargs)
     except directors.SkipFileError:
         pass
     if report_errors and errorlog:
         errorlog.print_to_stderr()
         self.fail("Checker found {} errors:\n{}".format(
             len(errorlog), errorlog))
Ejemplo n.º 2
0
 def Check(self,
           code,
           pythonpath=(),
           skip_repeat_calls=True,
           report_errors=True,
           filename=None,
           quick=False,
           **kwargs):
     """Run an inference smoke test for the given code."""
     self.ConfigureOptions(skip_repeat_calls=skip_repeat_calls,
                           pythonpath=pythonpath,
                           quick=quick)
     errorlog = errors.ErrorLog()
     try:
         analyze.check_types(textwrap.dedent(code),
                             filename,
                             loader=self.loader,
                             errorlog=errorlog,
                             options=self.options,
                             **kwargs)
     except directors.SkipFile:
         pass
     if report_errors and errorlog:
         errorlog.print_to_stderr()
         self.fail("Checker found {} errors:\n{}".format(
             len(errorlog), errorlog))
Ejemplo n.º 3
0
 def Check(self,
           code,
           pythonpath=(),
           skip_repeat_calls=True,
           report_errors=True,
           filename=None,
           python_version=None,
           **kwargs):
     """Run an inference smoke test for the given code."""
     self.options.tweak(skip_repeat_calls=skip_repeat_calls,
                        pythonpath=pythonpath,
                        python_version=python_version)
     errorlog = errors.ErrorLog()
     self._CreateLoader()
     try:
         analyze.check_types(textwrap.dedent(code),
                             filename,
                             loader=self.loader,
                             errorlog=errorlog,
                             options=self.options,
                             **kwargs)
     except directors.SkipFile:
         pass
     if report_errors and len(errorlog):
         errorlog.print_to_stderr()
         self.fail("Checker found %d errors" % len(errorlog))
Ejemplo n.º 4
0
 def CheckWithErrors(self, code, deep=True, pythonpath=(),
                     analyze_annotated=True, quick=False, **kwargs):
   kwargs.update(
       self._SetUpErrorHandling(code, pythonpath, analyze_annotated, quick))
   analyze.check_types(filename="<inline>", deep=deep, **kwargs)
   errorlog = kwargs["errorlog"]
   errorlog.assert_errors_match_expected()
   return errorlog
Ejemplo n.º 5
0
 def CheckWithErrors(self,
                     code,
                     deep=True,
                     pythonpath=(),
                     python_version=None,
                     **kwargs):
     kwargs.update(
         self._SetUpErrorHandling(code, pythonpath, python_version))
     analyze.check_types(filename="<inline>", deep=deep, **kwargs)
     return kwargs["errorlog"]