예제 #1
0
    def get_result_str(self, use_color=False):
        wrapper = TextWrapper(width=80,
                              initial_indent=" " * 4,
                              subsequent_indent=" " * 6)

        if use_color:
            status_string = colorize(
                self.status, "GOOD") if self.status == "PASS" else colorize(
                    self.status, "BAD")
        else:
            status_string = self.status

        string = "{} [{}]\n".format(self.name, status_string)
        tolerances = self.tolerances
        if tolerances:
            string += "Tolerances:\n"
            for tolerance in tolerances:
                string += '\n'.join(
                    wrapper.wrap("- " + tolerance.get_definition_str())) + "\n"
        if self.detailed_report:
            string += "Detailed Report:\n"
            string += '\n'.join(
                ['    ' + line for line in self.detailed_report.split('\n')])

        return string
예제 #2
0
    def execute(self):
        base_report_dir = self.report_dir
        report = ""
        total_status = True

        for color in self.color_list:
            print(
                colorize("Running color test for {}".format(color.name),
                         "HEADER"))
            input("Press ENTER to continue...")
            report += "Color test for {} =============\n".format(color.name)
            self.current_color = color
            self.report_dir = base_report_dir + "_{}".format(color.name)
            status = self.execute_single_color()
            report += self.detailed_report
            report += "Result: {}\n".format("PASS" if status else "FAIL")

            print(
                colorize("Status for color test at {}".format(color.name),
                         "HEADER"))
            print("Status: {}\n".format(
                colorize("PASS", "GOOD"
                         ) if status else colorize("FAIL", "BAD")))

            total_status = total_status and status

        self.detailed_report = report
        return total_status
예제 #3
0
    def run_tests(self):
        for test in self.tests:
            # Print test information and prompt user for confirmation
            start_string = "\nStarting test \"{}\"".format(test.name)
            print(colorize(start_string, "HEADER"))
            print(test.get_definition_str())
            test.run()

            # Print test results
            print(colorize("\nTest result", "HEADER"))
            print(test.get_result_str(True))
            input("Press ENTER to continue...\n")
            print(colorize("\nTest suite status", "HEADER"))
            print(self.get_progress_str())
예제 #4
0
    def get_list_entry_str(self, color, num):
        status = "    "
        if self.status != "NOT_RUN":
            status = self.status
            if color:
                if status == "PASS":
                    status = colorize(status, "GOOD")
                if status == "FAIL":
                    status = colorize(status, "BAD")
                if status == "SKIP":
                    status = colorize(status, "WARN")

        return "[{status}] {num}. {name}\n".format(status=status,
                                                   num=num,
                                                   name=self.name)
예제 #5
0
def write_report():
    report_file = '{}/report.txt'.format(args.report_dir)

    with open(report_file, 'w') as f:
        f.write(test_runner.to_report())

    print("--- Test Summary ---")
    print(test_runner.print_summary())
    print("\nReport was written to - {}".format(
        colorize(args.report_dir, "HEADER")))
예제 #6
0
    def print_summary(self, color=True):
        summary = ""
        total_tests = len(self.tests)
        passed_tests = len(
            [test for test in self.tests if test.status == "PASS"])
        failed_tests = len(
            [test for test in self.tests if test.status == "FAIL"])
        skipped_tests = len(
            [test for test in self.tests if test.status == "SKIP"])
        failed_test_list = [
            test for test in self.tests if test.status == "FAIL"
        ]

        if color:
            overall_status = colorize("PASS", "GOOD") if (
                failed_tests == 0 and skipped_tests == 0) else colorize(
                    "FAIL", "BAD")
        else:
            overall_status = "PASS" if (failed_tests == 0
                                        and skipped_tests == 0) else "FAIL"
        summary += ("Overall status: {status}\n"
                    "\n"
                    "Passed:  {passed}/{total}\n"
                    "Failed:  {failed}/{total}\n"
                    "Skipped: {skipped}/{total}\n").format(
                        status=overall_status,
                        passed=passed_tests,
                        failed=failed_tests,
                        skipped=skipped_tests,
                        total=total_tests)

        if failed_test_list:
            summary += "The following tests failed:\n"
            for test in failed_test_list:
                summary += " - {}\n".format(test.name)

        summary += "\n"
        summary += self.get_progress_str(color)
        return summary
예제 #7
0
 def override_tolerances(self):
     for tolerance in self.tolerances:
         print(
             colorize("\nOverriding tolerance " + tolerance.name, "HEADER"))
         print(tolerance.get_definition_str())
         valid = False
         while not valid:
             value = input("Enter new value: ")
             try:
                 tolerance.set(value)
                 valid = True
             except BaseException as e:
                 print("Error setting tolerance: ", str(e))
예제 #8
0
    def execute(self):
        self.detailed_report = ""
        depth_range = self.sensor_spec["max_depth"] - self.sensor_spec[
            "min_depth"]
        self.depth_list = [
            (1 / 4) * depth_range + self.sensor_spec["min_depth"],
            (2 / 4) * depth_range + self.sensor_spec["min_depth"],
            (3 / 4) * depth_range + self.sensor_spec["min_depth"]
        ]
        self.prompt_depth_list()

        base_report_dir = self.report_dir
        report = ""
        total_status = True
        for depth in self.depth_list:
            print(
                colorize("Running range test for range {}m".format(depth),
                         "HEADER"))
            input("Press ENTER to continue...")
            report += "Depth test at {}m =============\n".format(depth)
            self.current_depth = depth
            self.report_dir = base_report_dir + "_{}m".format(depth)
            status = super().execute()
            report += self.detailed_report
            report += "Result: {}\n".format("PASS" if status else "FAIL")

            print(
                colorize("Status for range test at {}m".format(depth),
                         "HEADER"))
            print("Status: {}".format(
                colorize("PASS", "GOOD"
                         ) if status else colorize("FAIL", "BAD")))
            print(self.detailed_report)

            total_status = total_status and status

        self.detailed_report = report
        return total_status
예제 #9
0
    def do_setup(self, app):
        time.sleep(10)

        # Scene setup instructions for the user
        print(colorize("\nTest setup:", "HEADER"))
        table = Texttable()
        table.add_rows([
            ["Target", "Description"],
            ["Target Choice", "April Tags Fiducial Marker"],
            [
                "Target Details",
                "A single april tag marker in the tag36h11 family is required for this testcase. "
                "The ID of the tag does not matter. PDF copies of tags of the correct family "
                "can be found at the link provided in the 'Test Scene Materials' section of the "
                "user guide and can be printed out and used in the test."
            ],
            [
                "Target Location",
                "Place the target in the target region in the field of "
                "view of the camera. The target region is shown as the area within the green box "
                "in the image viewer."
            ]
        ])
        print(table.draw())
        print(
            "\nPlease navigate to http://<Target_IP>:3000 in your web browser to see "
            "the image viewer. Place the april tag marker in the line of sight of camera "
            "within the target area specified by the green rectangle.")
        print(
            "Adjust the position of the april tag marker "
            "in the viewer such that on the image viewer the marker is fully within the "
            "target area (within the green box). A green semi-transparent rectangle is "
            "overlaid on top of detected april tags and defines the detected tag's borders.\n"
        )

        # Allow the user to confirm the scene is correctly setup
        setup_done = ""
        while setup_done not in ['c']:
            setup_done = input(
                "Press 'c' to confirm completed scene setup and continue:")
예제 #10
0
    def do_setup(self, app):
        time.sleep(10)
        print(colorize("\nTest setup:", "HEADER"))

        split_mode = self.sensor_spec["mode"].split('x')
        cols = int(split_mode[0])
        rows = int(split_mode[1])

        # How much of the image the target should consume
        # as specified for the user
        width_ratio = 1 / 15
        height_ratio = 1 / 15

        target_height_pixels = int(rows * height_ratio)
        target_width_pixels = int(cols * width_ratio)

        # Get sensor focal length
        fx = self.sensor_spec["depth_focal_length_x"]
        fy = self.sensor_spec["depth_focal_length_y"]

        # Distance for color test
        depth = 0.5

        # Target size (in meters) to have the desired apparent size (in pixels)
        target_width = depth * target_width_pixels / fx
        target_height = depth * target_height_pixels / fy

        # Lego 2x4 block dimentions in meters
        lego_width = 0.032
        lego_height = 0.01

        target_width_in_legos = int(max(ceil(target_width / lego_width), 2))
        target_height_in_legos = int(max(ceil(target_height / lego_height), 2))

        table = Texttable()
        table.add_rows([
            ["Target", "Description"],
            ["Target Choice", "Classic Lego brick 2x4"],
            [
                "Target Size",
                ("Based on FOV & sensor mode, a solid {color} colored target of a minimum "
                 "size of {width:.2f}cm wide by {height:.2f}cm high is required for this "
                 "testcase. Please see the documentation on how to build a lego target "
                 "that is {lego_w} bricks wide by {lego_h} bricks "
                 "high.").format(color=self.current_color.name,
                                 width=target_width * 100.0,
                                 height=target_height * 100.0,
                                 lego_w=target_width_in_legos,
                                 lego_h=target_height_in_legos)
            ],
            [
                "Target Location",
                "Place the target in the field of view of the camera at a "
                "distance of {:.3f}m from the camera".format(depth)
            ]
        ])
        print(table.draw())

        print(
            "\nPlease navigate to http://<Target_IP>:3000 in your web browser to see "
            "the image viewer. Place the {} colored target in the line of sight of camera "
            "at a distance of {:.3f}m.".format(self.current_color.name, depth))
        print(
            "Adjust the position of the lego target or the green box (with the cross mark) "
            "in the viewer while maintaining the lego target's distance such that on the image "
            "viewer the green box lands on "
            "the {} colored lego target.".format(self.current_color.name))
        print(
            "Refer to 'Setup Test Scenes' section in the user guide for example.\n"
        )

        target_cmd = ""
        print(
            "Use 'w','a','s','d' to move green box up, left, down, right or 'c' to run the test"
        )
        while target_cmd not in ['c']:
            target_cmd = getch.getch()
            if target_cmd == 'w':
                app.nodes["evaluator"].components["ColorEvaluator"].config[
                    "target_cmd"] = 1
            elif target_cmd == 's':
                app.nodes["evaluator"].components["ColorEvaluator"].config[
                    "target_cmd"] = 2
            elif target_cmd == 'a':
                app.nodes["evaluator"].components["ColorEvaluator"].config[
                    "target_cmd"] = 3
            elif target_cmd == 'd':
                app.nodes["evaluator"].components["ColorEvaluator"].config[
                    "target_cmd"] = 4
            elif target_cmd == 'c':
                app.nodes["evaluator"].components["ColorEvaluator"].config[
                    "target_cmd"] = 5