Beispiel #1
0
  def assert_checker(self, relpath, contents, expected_code=0, expected_message=''):
    with temporary_dir() as td:
      with safe_open(os.path.join(td, relpath), 'w') as fp:
        fp.write(contents)

      args=['--root-dir={}'.format(td)]
      for plugin_type in checker.plugins():
        opts = {'skip': False, 'max_length': self._MAX_LENGTH, 'ignore': ['E111']}
        args.append('--{}-options={}'.format(plugin_type.name(), json.dumps(opts)))
      args.append(relpath)

      with open(os.path.join(td, 'stdout'), 'w+') as stdout:
        with open(os.path.join(td, 'stderr'), 'w+') as stderr:
          with stdio_as(stdout_fd=stdout.fileno(), stderr_fd=stderr.fileno(), stdin_fd=-1):
            with self.assertRaises(SystemExit) as error:
              checker.main(args=args)

          def read_stdio(fp):
            fp.flush()
            fp.seek(0)
            return fp.read()

          self.assertEqual(expected_code, error.exception.code,
                           'STDOUT:\n{}\nSTDERR:\n{}'.format(read_stdio(stdout),
                                                             read_stdio(stderr)))

          self.assertEqual(expected_message, read_stdio(stdout).strip())
          self.assertEqual('', read_stdio(stderr))
    def assert_checker(self, relpath, contents, expected_code=0, expected_message=""):
        with temporary_dir() as td:
            with safe_open(os.path.join(td, relpath), "w") as fp:
                fp.write(contents)

            args = ["--root-dir={}".format(td)]
            for plugin_type in checker.plugins():
                opts = {"skip": False, "max_length": self._MAX_LENGTH, "ignore": ["E111"]}
                args.append("--{}-options={}".format(plugin_type.name(), json.dumps(opts)))
            args.append(relpath)

            with open(os.path.join(td, "stdout"), "w+") as stdout:
                with open(os.path.join(td, "stderr"), "w+") as stderr:
                    with stdio_as(
                        stdout_fd=stdout.fileno(), stderr_fd=stderr.fileno(), stdin_fd=-1
                    ):
                        with self.assertRaises(SystemExit) as error:
                            checker.main(args=args)

                    def read_stdio(fp):
                        fp.flush()
                        fp.seek(0)
                        return fp.read()

                    self.assertEqual(
                        expected_code,
                        error.exception.code,
                        "STDOUT:\n{}\nSTDERR:\n{}".format(read_stdio(stdout), read_stdio(stderr)),
                    )

                    self.assertEqual(expected_message, read_stdio(stdout).strip())
                    self.assertEqual("", read_stdio(stderr))
Beispiel #3
0
 def plugin_subsystems(cls):
     subsystem_type_by_plugin_type = factory_dict(
         default_subsystem_for_plugin)
     subsystem_type_by_plugin_type.update(
         (subsystem_type.plugin_type(), subsystem_type)
         for subsystem_type in cls._CUSTOM_PLUGIN_SUBSYSTEMS)
     return tuple(subsystem_type_by_plugin_type[plugin_type]
                  for plugin_type in checker.plugins())
Beispiel #4
0
 def plugin_subsystems(cls):
   subsystem_type_by_plugin_type = factory_dict(default_subsystem_for_plugin)
   subsystem_type_by_plugin_type.update((subsystem_type.plugin_type(), subsystem_type)
                                        for subsystem_type in cls._CUSTOM_PLUGIN_SUBSYSTEMS)
   return tuple(subsystem_type_by_plugin_type[plugin_type] for plugin_type in checker.plugins())