Esempio n. 1
0
    def test_print_dict_objects(self):
        class SomeStruct(object):
            def __init__(self, a, b):
                self.a = a
                self.b = b

            @property
            def c(self):
                return self.a + self.b

            def foo(self):
                pass

            @classmethod
            def bar(cls):
                pass

            @staticmethod
            def foobar():
                pass

        out = six.StringIO()
        formatters = {"c": lambda x: "a + b = %s" % x.c}
        cliutils.print_dict(SomeStruct(1, 2), formatters=formatters, out=out)
        self.assertEqual(
            "+----------+-----------+\n"
            "| Property | Value     |\n"
            "+----------+-----------+\n"
            "| a        | 1         |\n"
            "| b        | 2         |\n"
            "| c        | a + b = 3 |\n"
            "+----------+-----------+\n", out.getvalue())
Esempio n. 2
0
    def show_verifier(self, api, verifier_id=None):
        """Show detailed information about a verifier."""

        verifier = api.verifier.get(verifier_id=verifier_id)
        fields = [
            "UUID", "Status", "Created at", "Updated at", "Active", "Name",
            "Description", "Type", "Platform", "Source", "Version",
            "System-wide", "Extra settings", "Location", "Venv location"
        ]
        used_verifier = envutils.get_global(envutils.ENV_VERIFIER)
        formatters = {
            "Created at":
            lambda v: v["created_at"].replace("T", " "),
            "Updated at":
            lambda v: v["updated_at"].replace("T", " "),
            "Active":
            lambda v: (ACTIVE if v["uuid"] == used_verifier else None),
            "Extra settings":
            lambda v: (json.dumps(v["extra_settings"], indent=4)
                       if v["extra_settings"] else None),
            "Location":
            lambda v: self._get_location((v["uuid"]), "repo")
        }
        if not verifier["system_wide"]:
            formatters["Venv location"] = lambda v: self._get_location(
                v["uuid"], ".venv")
        cliutils.print_dict(verifier,
                            fields=fields,
                            formatters=formatters,
                            normalize_field_names=True,
                            print_header=False,
                            table_label="Verifier")
        print("Attention! All you do in the verifier repository or verifier "
              "virtual environment, you do it at your own risk!")
Esempio n. 3
0
    def show_verifier(self, api, verifier_id=None):
        """Show detailed information about a verifier."""

        verifier = api.verifier.get(verifier_id=verifier_id)
        fields = ["UUID", "Status", "Created at", "Updated at", "Active",
                  "Name", "Description", "Type", "Platform", "Source",
                  "Version", "System-wide", "Extra settings", "Location",
                  "Venv location"]
        used_verifier = envutils.get_global(envutils.ENV_VERIFIER)
        formatters = {
            "Created at": lambda v: v["created_at"].replace("T", " "),
            "Updated at": lambda v: v["updated_at"].replace("T", " "),
            "Active": lambda v: u"\u2714"
                                if v["uuid"] == used_verifier else None,
            "Extra settings": lambda v: (json.dumps(v["extra_settings"],
                                                    indent=4)
                                         if v["extra_settings"] else None),
            "Location": lambda v: self._get_location((v["uuid"]), "repo")
        }
        if not verifier["system_wide"]:
            formatters["Venv location"] = lambda v: self._get_location(
                v["uuid"], ".venv")
        cliutils.print_dict(verifier, fields=fields, formatters=formatters,
                            normalize_field_names=True, print_header=False,
                            table_label="Verifier")
        print("Attention! All you do in the verifier repository or verifier "
              "virtual environment, you do it at your own risk!")
Esempio n. 4
0
 def show_verifier(self, api, verifier_id=None):
     """Show detailed information about a verifier."""
     verifier = api.verifier.get(verifier_id)
     fields = [
         "UUID", "Status", "Created at", "Updated at", "Active", "Name",
         "Description", "Type", "Namespace", "Source", "Version",
         "System-wide", "Extra settings", "Location"
     ]
     used_verifier = envutils.get_global(envutils.ENV_VERIFIER)
     formatters = {
         "Created at":
         lambda v: v.created_at.replace(microsecond=0),
         "Updated at":
         lambda v: v.updated_at.replace(microsecond=0),
         "Active":
         lambda v: u"\u2714" if v.uuid == used_verifier else None,
         "Extra settings":
         lambda v: (json.dumps(v.extra_settings, indent=4)
                    if v.extra_settings else None),
         "Location":
         lambda v: v.manager.repo_dir
     }
     if not verifier.system_wide:
         fields.append("Venv location")
         formatters["Venv location"] = lambda v: v.manager.venv_dir
     cliutils.print_dict(verifier,
                         fields=fields,
                         formatters=formatters,
                         normalize_field_names=True,
                         print_header=False,
                         table_label="Verifier")
     print(
         _("Attention! All you do in the verifier repository or "
           "verifier virtual environment, you do it at your own risk!"))
Esempio n. 5
0
    def test_print_dict_objects(self):
        class SomeStruct(object):
            def __init__(self, a, b):
                self.a = a
                self.b = b

            @property
            def c(self):
                return self.a + self.b

            def foo(self):
                pass

            @classmethod
            def bar(cls):
                pass

            @staticmethod
            def foobar():
                pass

        out = six.StringIO()
        formatters = {"c": lambda x: "a + b = %s" % x.c}
        cliutils.print_dict(SomeStruct(1, 2), formatters=formatters, out=out)
        self.assertEqual("+----------+-----------+\n"
                         "| Property | Value     |\n"
                         "+----------+-----------+\n"
                         "| a        | 1         |\n"
                         "| b        | 2         |\n"
                         "| c        | a + b = 3 |\n"
                         "+----------+-----------+\n",
                         out.getvalue())
Esempio n. 6
0
 def test_print_dict(self):
     out = six.StringIO()
     dict = {"key": "value"}
     cliutils.print_dict(dict, out=out)
     self.assertEqual(
         "+----------+-------+\n"
         "| Property | Value |\n"
         "+----------+-------+\n"
         "| key      | value |\n"
         "+----------+-------+\n", out.getvalue())
Esempio n. 7
0
 def test_print_dict(self):
     out = six.StringIO()
     dict = {"key": "value"}
     cliutils.print_dict(dict, out=out)
     self.assertEqual("+----------+-------+\n"
                      "| Property | Value |\n"
                      "+----------+-------+\n"
                      "| key      | value |\n"
                      "+----------+-------+\n",
                      out.getvalue())
Esempio n. 8
0
 def test_print_dict_with_spec_chars(self):
     out = six.StringIO()
     dict = {"key": "line1\r\nline2"}
     cliutils.print_dict(dict, out=out)
     self.assertEqual("+----------+-------+\n"
                      "| Property | Value |\n"
                      "+----------+-------+\n"
                      "| key      | line1 |\n"
                      "|          | line2 |\n"
                      "+----------+-------+\n",
                      out.getvalue())
Esempio n. 9
0
 def test_print_dict_header(self):
     out = six.StringIO()
     dict = {"key": "value"}
     cliutils.print_dict(dict, table_label="Some Table", print_header=False,
                         out=out)
     self.assertEqual("+-------------+\n"
                      "| Some Table  |\n"
                      "+-----+-------+\n"
                      "| key | value |\n"
                      "+-----+-------+\n",
                      out.getvalue())
Esempio n. 10
0
 def test_print_dict_header(self):
     out = six.StringIO()
     dict = {"key": "value"}
     cliutils.print_dict(dict, table_label="Some Table", print_header=False,
                         out=out)
     self.assertEqual("+-------------+\n"
                      "| Some Table  |\n"
                      "+-----+-------+\n"
                      "| key | value |\n"
                      "+-----+-------+\n",
                      out.getvalue())
Esempio n. 11
0
 def test_print_dict_with_spec_chars(self):
     out = six.StringIO()
     dict = {"key": "line1\r\nline2"}
     cliutils.print_dict(dict, out=out)
     self.assertEqual(
         "+----------+-------+\n"
         "| Property | Value |\n"
         "+----------+-------+\n"
         "| key      | line1 |\n"
         "|          | line2 |\n"
         "+----------+-------+\n", out.getvalue())
Esempio n. 12
0
 def test_print_dict_wrap(self):
     out = six.StringIO()
     dict = {"key1": "not wrapped", "key2": "this will be wrapped"}
     cliutils.print_dict(dict, wrap=16, out=out)
     self.assertEqual(
         "+----------+--------------+\n"
         "| Property | Value        |\n"
         "+----------+--------------+\n"
         "| key1     | not wrapped  |\n"
         "| key2     | this will be |\n"
         "|          | wrapped      |\n"
         "+----------+--------------+\n", out.getvalue())
Esempio n. 13
0
 def test_print_dict_wrap(self):
     out = six.StringIO()
     dict = {"key1": "not wrapped",
             "key2": "this will be wrapped"}
     cliutils.print_dict(dict, wrap=16, out=out)
     self.assertEqual("+----------+--------------+\n"
                      "| Property | Value        |\n"
                      "+----------+--------------+\n"
                      "| key1     | not wrapped  |\n"
                      "| key2     | this will be |\n"
                      "|          | wrapped      |\n"
                      "+----------+--------------+\n",
                      out.getvalue())
Esempio n. 14
0
 def test_print_dict_formatters_and_fields(self):
     out = six.StringIO()
     dict = {"key1": "value", "key2": "Value", "key3": "vvv"}
     formatters = {"foo": lambda x: x["key1"], "bar": lambda x: x["key2"]}
     fields = ["foo", "bar"]
     cliutils.print_dict(dict,
                         formatters=formatters,
                         fields=fields,
                         out=out)
     self.assertEqual(
         "+----------+-------+\n"
         "| Property | Value |\n"
         "+----------+-------+\n"
         "| foo      | value |\n"
         "| bar      | Value |\n"
         "+----------+-------+\n", out.getvalue())
Esempio n. 15
0
 def test_print_dict_formatters_and_fields(self):
     out = six.StringIO()
     dict = {"key1": "value",
             "key2": "Value",
             "key3": "vvv"}
     formatters = {"foo": lambda x: x["key1"],
                   "bar": lambda x: x["key2"]}
     fields = ["foo", "bar"]
     cliutils.print_dict(dict, formatters=formatters, fields=fields,
                         out=out)
     self.assertEqual("+----------+-------+\n"
                      "| Property | Value |\n"
                      "+----------+-------+\n"
                      "| foo      | value |\n"
                      "| bar      | Value |\n"
                      "+----------+-------+\n",
                      out.getvalue())
Esempio n. 16
0
    def show(self,
             api,
             verification_uuid=None,
             sort_by="name",
             detailed=False):
        """Show detailed information about a verification."""

        verification = api.verification.get(
            verification_uuid=verification_uuid)
        verifier = api.verifier.get(verifier_id=verification["verifier_uuid"])
        deployment = api.deployment.get(
            deployment=verification["deployment_uuid"])

        def run_args_formatter(v):
            run_args = []
            for k in sorted(v["run_args"]):
                if k in ("load_list", "skip_list", "xfail_list"):
                    value = "(value is too long, %s)"
                    if detailed:
                        value %= "will be displayed separately"
                    else:
                        value %= "use 'detailed' flag to display it"
                else:
                    value = v["run_args"][k]
                run_args.append("%s: %s" % (k, value))
            return "\n".join(run_args)

        # Main table
        fields = [
            "UUID", "Status", "Started at", "Finished at", "Duration",
            "Run arguments", "Tags", "Verifier name", "Verifier type",
            "Deployment name", "Tests count", "Tests duration, sec", "Success",
            "Skipped", "Expected failures", "Unexpected success", "Failures"
        ]
        formatters = {
            "Started at":
            lambda v: v["created_at"].replace("T", " "),
            "Finished at":
            lambda v: v["updated_at"].replace("T", " "),
            "Duration":
            lambda v: (dt.datetime.strptime(v["updated_at"], TIME_FORMAT) - dt.
                       datetime.strptime(v["created_at"], TIME_FORMAT)),
            "Run arguments":
            run_args_formatter,
            "Tags":
            lambda v: ", ".join(v["tags"]) or None,
            "Verifier name":
            lambda v: "%s (UUID: %s)" % (verifier["name"], verifier["uuid"]),
            "Verifier type": (lambda v: "%s (platform: %s)" %
                              (verifier["type"], verifier["platform"])),
            "Deployment name": (lambda v: "%s (UUID: %s)" %
                                (deployment["name"], deployment["uuid"])),
            "Tests duration, sec":
            lambda v: v["tests_duration"]
        }
        cliutils.print_dict(verification,
                            fields,
                            formatters=formatters,
                            normalize_field_names=True,
                            print_header=False,
                            table_label="Verification")

        if detailed:
            h = "Run arguments"
            print("\n%s" % cliutils.make_header(h, len(h)).strip())
            print("\n%s\n" % json.dumps(verification["run_args"], indent=4))

        # Tests table
        tests = verification["tests"]
        values = [tests[test_id] for test_id in tests]
        fields = ["Name", "Duration, sec", "Status"]
        formatters = {"Duration, sec": lambda v: v["duration"]}
        index = ("name", "duration", "status").index(sort_by)
        cliutils.print_list(values,
                            fields,
                            formatters=formatters,
                            table_label="Tests",
                            normalize_field_names=True,
                            sortby_index=index)

        if detailed:
            failures = [t for t in tests.values() if t["status"] == "fail"]
            if failures:
                self._print_failures("Failures", failures)
            else:
                print("\nCongratulations! Verification passed all tests ;)")
Esempio n. 17
0
    def show(self, api, verification_uuid=None, sort_by="name",
             detailed=False):
        """Show detailed information about a verification."""

        verification = api.verification.get(
            verification_uuid=verification_uuid)
        verifier = api.verifier.get(verifier_id=verification["verifier_uuid"])
        deployment = api.deployment.get(
            deployment=verification["deployment_uuid"])

        def run_args_formatter(v):
            run_args = []
            for k in sorted(v["run_args"]):
                if k in ("load_list", "skip_list", "xfail_list"):
                    value = "(value is too long, %s)"
                    if detailed:
                        value %= "will be displayed separately"
                    else:
                        value %= "use 'detailed' flag to display it"
                else:
                    value = v["run_args"][k]
                run_args.append("%s: %s" % (k, value))
            return "\n".join(run_args)

        # Main table
        fields = ["UUID", "Status", "Started at", "Finished at", "Duration",
                  "Run arguments", "Tags", "Verifier name", "Verifier type",
                  "Deployment name", "Tests count", "Tests duration, sec",
                  "Success", "Skipped", "Expected failures",
                  "Unexpected success", "Failures"]
        formatters = {
            "Started at": lambda v: v["created_at"].replace("T", " "),
            "Finished at": lambda v: v["updated_at"].replace("T", " "),
            "Duration": lambda v: (dt.datetime.strptime(v["updated_at"],
                                                        TIME_FORMAT) -
                                   dt.datetime.strptime(v["created_at"],
                                                        TIME_FORMAT)),
            "Run arguments": run_args_formatter,
            "Tags": lambda v: ", ".join(v["tags"]) or None,
            "Verifier name": lambda v: "%s (UUID: %s)" % (verifier["name"],
                                                          verifier["uuid"]),
            "Verifier type": (
                lambda v: "%s (platform: %s)" % (verifier["type"],
                                                 verifier["platform"])),
            "Deployment name": (
                lambda v: "%s (UUID: %s)" % (deployment["name"],
                                             deployment["uuid"])),
            "Tests duration, sec": lambda v: v["tests_duration"]
        }
        cliutils.print_dict(verification, fields, formatters=formatters,
                            normalize_field_names=True, print_header=False,
                            table_label="Verification")

        if detailed:
            h = "Run arguments"
            print("\n%s" % cliutils.make_header(h, len(h)).strip())
            print("\n%s\n" % json.dumps(verification["run_args"], indent=4))

        # Tests table
        tests = verification["tests"]
        values = [tests[test_id] for test_id in tests]
        fields = ["Name", "Duration, sec", "Status"]
        formatters = {"Duration, sec": lambda v: v["duration"]}
        index = ("name", "duration", "status").index(sort_by)
        cliutils.print_list(values, fields, formatters=formatters,
                            table_label="Tests", normalize_field_names=True,
                            sortby_index=index)

        if detailed:
            failures = [t for t in tests.values() if t["status"] == "fail"]
            if failures:
                self._print_failures("Failures", failures)
            else:
                print("\nCongratulations! Verification passed all tests ;)")