예제 #1
0
 def __call__(self, record):
     if (record.outcome == test_record.Outcome.ABORTED
             and record.dut_id == DEFAULT_DUT_ID):
         console_output.cli_print(
             'Test was aborted at test start. Skipping output to JSON.')
     else:
         console_output.cli_print('Outputting test record to JSON.')
         super(CustomOutputToJSON, self).__call__(record)
 def __call__(self, record):
   if (record.outcome == test_record.Outcome.ABORTED
       and record.dut_id == DEFAULT_DUT_ID):
     console_output.cli_print(
         'Test was aborted at test start. Skipping output to JSON.')
   else:
     console_output.cli_print('Outputting test record to JSON.')
     super(CustomOutputToJSON, self).__call__(record)
예제 #3
0
    def run(self):
        """Main logic for this thread to execute."""
        try:
            if platform.system() == 'Windows':
                # Windows doesn't support file-like objects for select(), so fall back
                # to raw_input().
                response = input(''.join((self._message, os.linesep, PROMPT)))
                self._answered = True
                self._callback(response)
            else:
                # First, display the prompt to the console.
                console_output.cli_print(self._message,
                                         color=self._color,
                                         end=os.linesep,
                                         logger=None)
                console_output.cli_print(PROMPT,
                                         color=self._color,
                                         end='',
                                         logger=None)
                sys.stdout.flush()

                # Before reading, clear any lingering buffered terminal input.
                if sys.stdin.isatty():
                    termios.tcflush(sys.stdin, termios.TCIFLUSH)

                # Although this isn't threadsafe with do_setlocale=True, it doesn't work without it.
                encoding = locale.getpreferredencoding(do_setlocale=True)

                line = u''
                while not self._stopped:
                    inputs, _, _ = select.select([sys.stdin], [], [], 0.001)
                    for stream in inputs:
                        if stream is sys.stdin:
                            new = os.read(sys.stdin.fileno(), 1024)
                            if not new:
                                # Hit EOF!
                                if not sys.stdin.isatty():
                                    # We're running in the background somewhere, so the only way
                                    # to respond to this prompt is the UI. Let's just wait for
                                    # that to happen now. We'll give them a week :)
                                    print(
                                        "Waiting for a non-console response.")
                                    time.sleep(60 * 60 * 24 * 7)
                                else:
                                    # They hit ^D (to insert EOF). Tell them to hit ^C if they
                                    # want to actually quit.
                                    print("Hit ^C (Ctrl+c) to exit.")
                                    break
                            line += new.decode(encoding)
                            if '\n' in line:
                                response = line[:line.find('\n')]
                                self._answered = True
                                self._callback(response)
                            return
        finally:
            self._stopped = True
예제 #4
0
 def Stop(self):
     """Mark this ConsolePrompt as stopped."""
     self._stop_event.set()
     if not self._answered:
         console_output.cli_print(os.linesep,
                                  color=self._color,
                                  end='',
                                  logger=None)
         _LOG.debug(
             'Stopping ConsolePrompt--prompt was answered from elsewhere.')
예제 #5
0
  def run(self):
    """Main logic for this thread to execute."""
    try:
      if platform.system() == 'Windows':
        # Windows doesn't support file-like objects for select(), so fall back
        # to raw_input().
        response = input(''.join((self._message,
                                  os.linesep,
                                  PROMPT)))
        self._answered = True
        self._callback(response)
      else:
        # First, display the prompt to the console.
        console_output.cli_print(self._message, color=self._color,
                                 end=os.linesep, logger=None)
        console_output.cli_print(PROMPT, color=self._color, end='', logger=None)
        sys.stdout.flush()

        # Before reading, clear any lingering buffered terminal input.
        if sys.stdin.isatty():
          termios.tcflush(sys.stdin, termios.TCIFLUSH)

        line = ''
        while not self._stopped:
          inputs, _, _ = select.select([sys.stdin], [], [], 0.001)
          for stream in inputs:
            if stream is sys.stdin:
              new = os.read(sys.stdin.fileno(), 1024)
              if not new:
                # Hit EOF!
                if not sys.stdin.isatty():
                  # We're running in the background somewhere, so the only way
                  # to respond to this prompt is the UI. Let's just wait for
                  # that to happen now. We'll give them a week :)
                  print("Waiting for a non-console response.")
                  time.sleep(60*60*24*7)
                else:
                  # They hit ^D (to insert EOF). Tell them to hit ^C if they
                  # want to actually quit.
                  print("Hit ^C (Ctrl+c) to exit.")
                  break
              line += new.decode('utf-8')
              if '\n' in line:
                response = line[:line.find('\n')]
                self._answered = True
                self._callback(response)
              return
    finally:
      self._stopped = True
예제 #6
0
    def run(self):
        """Main logic for this thread to execute."""
        if platform.system() == 'Windows':
            # Windows doesn't support file-like objects for select(), so fall back
            # to raw_input().
            response = input(''.join((self._message, os.linesep, PROMPT)))
            self._answered = True
            self._callback(response)
            return

        # First, display the prompt to the console.
        console_output.cli_print(self._message,
                                 color=self._color,
                                 end=os.linesep,
                                 logger=None)
        console_output.cli_print(PROMPT,
                                 color=self._color,
                                 end='',
                                 logger=None)
        sys.stdout.flush()

        # Before reading, clear any lingering buffered terminal input.
        termios.tcflush(sys.stdin, termios.TCIFLUSH)

        line = ''
        while not self._stop_event.is_set():
            inputs, _, _ = select.select([sys.stdin], [], [], 0.001)
            if sys.stdin in inputs:
                new = os.read(sys.stdin.fileno(), 1024)
                if not new:
                    # Hit EOF!
                    # They hit ^D (to insert EOF). Tell them to hit ^C if they
                    # want to actually quit.
                    print('Hit ^C (Ctrl+c) to exit.')
                    break
                line += new.decode('utf-8')
                if '\n' in line:
                    response = line[:line.find('\n')]
                    self._answered = True
                    self._callback(response)
                    return
        def wrapper(*args, **kwargs):
            mem.test_printer_counter += 1
            test_api = args[0]
            test_name = func.__name__

            # Print a banner. The test is about to begin
            console_output.banner_print(
                f'{mem.test_printer_counter:04}: {test_name}', logger=None)

            # And here's the test
            result = func(*args, **kwargs)

            # Check the result. Test phases do not need to return a result. In that
            # case, check for failed or unset measurements to determine pass or fail
            if not result:
                measurements = str(test_api.measurements)

                if "'FAIL'" in measurements or "'UNSET'" in measurements:
                    result_msg = "FAIL"

                else:
                    result_msg = "PASS"

            elif result.name == 'CONTINUE':
                result_msg = "PASS"

            elif result.name == 'SKIP':
                result_msg = "SKIP"

            else:
                result_msg = "FAIL"

            # Print the result
            console_output.cli_print(f"result: {result_msg}", logger=None)

            return result