コード例 #1
0
ファイル: test_metrics.py プロジェクト: evander-dacosta/dvc
    def test_wrong_type_show(self):
        with open("metric.unknown", "w+") as fd:
            fd.write("unknown")
            fd.flush()

        ret = main(["run", "-m", "metric.unknown"])
        self.assertEqual(ret, 0)

        with MockLoggerHandlers(logger.logger):
            reset_logger_standard_output()
            ret = main(
                [
                    "metrics",
                    "show",
                    "metric.unknown",
                    "-t",
                    "unknown",
                    "-x",
                    "0,0",
                ]
            )
            self.assertEqual(ret, 0)
            self.assertIn(
                "\tmetric.unknown: unknown",
                logger.logger.handlers[0].stream.getvalue(),
            )
コード例 #2
0
    def test_wrong_type_modify(self):
        with open("metric.unknown", "w+") as fd:
            fd.write("unknown")
            fd.flush()

        ret = main(["run", "-m", "metric.unknown"])
        self.assertEqual(ret, 0)

        with MockLoggerHandlers(logger.logger):
            logger.logger.handlers[1].stream = StringIO()
            ret = main(
                ["metrics", "modify", "metric.unknown", "-t", "unknown"])
            self.assertEqual(ret, 1)
            self.assertIn(
                "failed to modify metric file settings - metric type 'unknown'"
                " is not supported, must be one of [raw, json, csv, tsv, hcsv, htsv]",
                logger.logger.handlers[1].stream.getvalue(),
            )

            ret = main(["metrics", "modify", "metric.unknown", "-t", "CSV"])
            self.assertEqual(ret, 0)

            logger.logger.handlers[0].stream = StringIO()
            ret = main(["metrics", "show", "metric.unknown"])
            self.assertEqual(ret, 0)
            self.assertIn(
                "\tmetric.unknown: unknown",
                logger.logger.handlers[0].stream.getvalue(),
            )
コード例 #3
0
    def _test(self):
        url = get_local_url()
        self.main(["remote", "add", "-d", TEST_REMOTE, url])

        self.dvc.add(self.FOO)
        stage = self.dvc.run(deps=["foo"], outs=["bar"], cmd="echo bar > bar")
        self.main(["push"])

        stage_file_path = stage.relpath
        with open(stage_file_path, "r") as stage_file:
            content = yaml.safe_load(stage_file)
        del (content["outs"][0]["md5"])
        with open(stage_file_path, "w") as stage_file:
            yaml.dump(content, stage_file)

        with MockLoggerHandlers(logger.logger):
            logger.logger.handlers[0].stream = StringIO()
            self.main(["status", "-c"])
            self.assertIn(
                "Warning: Output 'bar'(Stage: 'bar.dvc') is "
                "missing version info. Cache for it will not be "
                "collected. Use dvc repro to get your pipeline up to "
                "date.",
                logger.logger.handlers[0].stream.getvalue(),
            )
コード例 #4
0
ファイル: test_metrics.py プロジェクト: evander-dacosta/dvc
    def test_wrong_type_add(self):
        with open("metric.unknown", "w+") as fd:
            fd.write("unknown")
            fd.flush()

        ret = main(["add", "metric.unknown"])
        self.assertEqual(ret, 0)

        with MockLoggerHandlers(logger.logger):
            reset_logger_error_output()
            ret = main(["metrics", "add", "metric.unknown", "-t", "unknown"])
            self.assertEqual(ret, 1)
            self.assertIn(
                "failed to add metric file 'metric.unknown' - metric type "
                "'unknown' is not supported, must be one of "
                "[raw, json, csv, tsv, hcsv, htsv]",
                logger.logger.handlers[1].stream.getvalue(),
            )

            ret = main(["metrics", "add", "metric.unknown", "-t", "raw"])
            self.assertEqual(ret, 0)

            reset_logger_standard_output()
            ret = main(["metrics", "show", "metric.unknown"])
            self.assertEqual(ret, 0)
            self.assertIn(
                "\tmetric.unknown: unknown",
                logger.logger.handlers[0].stream.getvalue(),
            )
コード例 #5
0
ファイル: test_repro.py プロジェクト: rpip/dvc
    def test(self):
        metrics_file = "metrics_file"
        metrics_value = 0.123489015
        ret = main([
            "run",
            "-m",
            metrics_file,
            "echo {} >> {}".format(metrics_value, metrics_file),
        ])
        self.assertEqual(0, ret)

        with MockLoggerHandlers(logger):
            reset_logger_standard_output()
            ret = main([
                "repro",
                "--force",
                "--metrics",
                metrics_file + Stage.STAGE_FILE_SUFFIX,
            ])
            self.assertEqual(0, ret)

            expected_metrics_display = "{}: {}".format(metrics_file,
                                                       metrics_value)
            self.assertIn(expected_metrics_display,
                          logger.handlers[0].stream.getvalue())
コード例 #6
0
    def _checkout_and_intercept_std_output(self):
        with MockLoggerHandlers(
                logger), ConsoleFontColorsRemover(), patch.object(
                    sys, "stdout") as stdout_mock:
            self.stdout_mock = logger.handlers[0].stream = stdout_mock

            ret = main(["checkout"])
            self.assertEqual(0, ret)
コード例 #7
0
ファイル: test_tag.py プロジェクト: rpip/dvc
    def test(self):
        ret = main(["add", self.FOO, self.BAR])
        self.assertEqual(ret, 0)

        with MockLoggerHandlers(logger), ConsoleFontColorsRemover():
            reset_logger_standard_output()

            ret = main(["tag", "list"])
            self.assertEqual(ret, 0)

            self.assertEqual("", logger.handlers[0].stream.getvalue())

        ret = main(["tag", "add", "v1"])
        self.assertEqual(ret, 0)

        with MockLoggerHandlers(logger), ConsoleFontColorsRemover():
            reset_logger_standard_output()

            ret = main(["tag", "list"])
            self.assertEqual(ret, 0)

            self.assertEqual(
                logger.handlers[0].stream.getvalue(),
                "bar.dvc:\n"
                "  bar:\n"
                "    v1:\n"
                "      md5: 8978c98bb5a48c2fb5f2c4c905768afa\n"
                "foo.dvc:\n"
                "  foo:\n"
                "    v1:\n"
                "      md5: acbd18db4cc2f85cedef654fccc4a4d8\n"
                "\n",
            )

        ret = main(["tag", "remove", "v1"])
        self.assertEqual(ret, 0)

        with MockLoggerHandlers(logger), ConsoleFontColorsRemover():
            reset_logger_standard_output()

            ret = main(["tag", "list"])
            self.assertEqual(ret, 0)

            self.assertEqual("", logger.handlers[0].stream.getvalue())
コード例 #8
0
ファイル: test_tag.py プロジェクト: rpip/dvc
    def test(self):
        ret = main(["run", "-o", self.FOO, "--no-exec"])
        self.assertEqual(ret, 0)

        with MockLoggerHandlers(logger), ConsoleFontColorsRemover():
            reset_logger_error_output()

            ret = main(["tag", "add", "v1", "foo.dvc"])
            self.assertEqual(ret, 0)

            self.assertEqual(
                "Warning: missing checksum info for 'foo'\n",
                logger.handlers[1].stream.getvalue(),
            )
コード例 #9
0
ファイル: test_tag.py プロジェクト: rpip/dvc
    def test(self):
        ret = main(["add", self.FOO])
        self.assertEqual(ret, 0)

        with MockLoggerHandlers(logger), ConsoleFontColorsRemover():
            reset_logger_error_output()

            ret = main(["tag", "remove", "v1", "foo.dvc"])
            self.assertEqual(ret, 0)

            self.assertEqual(
                "Warning: tag 'v1' not found for 'foo'\n",
                logger.handlers[1].stream.getvalue(),
            )
コード例 #10
0
    def test(self):
        with ConsoleFontColorsRemover(), MockLoggerHandlers(logger):
            reset_logger_error_output()

            main(["push"])
            self.stderr_contains_message()

            reset_logger_error_output()

            main(["pull"])
            self.stderr_contains_message()

            reset_logger_error_output()

            main(["status", "-c"])
            self.stderr_contains_message()
コード例 #11
0
ファイル: test_import.py プロジェクト: siddygups/dvc
    def _test(self, imp_urlparse_patch):
        with MockLoggerHandlers(logger.logger):
            logger.logger.handlers[1].stream = StringIO()
            page_address = "http://somesite.com/file_name"

            def dvc_exception(*args, **kwargs):
                raise DvcException("message")

            imp_urlparse_patch.side_effect = dvc_exception
            main(["import", page_address])
            self.assertIn(
                "Error: failed to import "
                "http://somesite.com/file_name. You could also try "
                "downloading it manually and adding it with `dvc add` "
                "command.",
                logger.logger.handlers[1].stream.getvalue(),
            )
コード例 #12
0
    def test(self):
        with MockLoggerHandlers(logger), ConsoleFontColorsRemover():
            logger.handlers[1].stream = StringIO()

            ret = main(["add", self.FOO])
            self.assertEqual(0, ret)

            foo_stage = os.path.abspath(self.FOO + Stage.STAGE_FILE_SUFFIX)

            # corrupt stage file
            with open(foo_stage, "a+") as file:
                file.write("this will break yaml file structure")

            ret = main(["add", self.BAR])
            self.assertEqual(1, ret)

            self.assertIn(
                "unable to read stage file: {} "
                "YAML file structure is corrupted".format(foo_stage),
                logger.handlers[1].stream.getvalue(),
            )
コード例 #13
0
ファイル: test_metrics.py プロジェクト: rpip/dvc
    def test_formatted_output(self):
        with open("metrics.csv", "w") as fobj:
            # Labels are in Spanish to test unicode characters
            fobj.write("valor_mse,desviación_mse,data_set\n"
                       "0.421601,0.173461,entrenamiento\n"
                       "0.67528,0.289545,pruebas\n"
                       "0.671502,0.297848,validación\n")

        with open("metrics.tsv", "w") as fobj:
            # Contains quoted newlines to test output correctness
            fobj.write("value_mse\tdeviation_mse\tdata_set\n"
                       "0.421601\t0.173461\ttrain\n"
                       '0.67528\t0.289545\t"test\\ning"\n'
                       "0.671502\t0.297848\tvalidation\n")

        with open("metrics.json", "w") as fobj:
            fobj.write("{\n"
                       '     "data_set": [\n'
                       '          "train",\n'
                       '          "testing",\n'
                       '          "validation"\n'
                       "     ],\n"
                       '     "deviation_mse": [\n'
                       '          "0.173461",\n'
                       '          "0.289545",\n'
                       '          "0.297848"\n'
                       "     ],\n"
                       '     "value_mse": [\n'
                       '          "0.421601",\n'
                       '          "0.67528",\n'
                       '          "0.671502"\n'
                       "     ]\n"
                       "}")

        with open("metrics.txt", "w") as fobj:
            fobj.write("ROC_AUC: 0.64\nKS: 78.9999999996\nF_SCORE: 77\n")

        self.dvc.run(
            fname="testing_metrics_output.dvc",
            metrics_no_cache=[
                "metrics.csv",
                "metrics.tsv",
                "metrics.json",
                "metrics.txt",
            ],
        )

        self.dvc.metrics.modify("metrics.csv", typ="csv")
        self.dvc.metrics.modify("metrics.tsv", typ="tsv")
        self.dvc.metrics.modify("metrics.json", typ="json")

        with MockLoggerHandlers(logger.logger):
            reset_logger_standard_output()

            ret = main(["metrics", "show"])
            self.assertEqual(ret, 0)

            expected_csv = (
                u"\tmetrics.csv:\n"
                u"\t\tvalor_mse   desviación_mse   data_set       \n"
                u"\t\t0.421601    0.173461         entrenamiento  \n"
                u"\t\t0.67528     0.289545         pruebas        \n"
                u"\t\t0.671502    0.297848         validación")

            expected_tsv = ("\tmetrics.tsv:\n"
                            "\t\tvalue_mse   deviation_mse   data_set    \n"
                            "\t\t0.421601    0.173461        train       \n"
                            "\t\t0.67528     0.289545        test\\ning   \n"
                            "\t\t0.671502    0.297848        validation")

            expected_txt = ("\tmetrics.txt:\n"
                            "\t\tROC_AUC: 0.64\n"
                            "\t\tKS: 78.9999999996\n"
                            "\t\tF_SCORE: 77\n")

            expected_json = ("\tmetrics.json:\n"
                             "\t\t{\n"
                             '\t\t     "data_set": [\n'
                             '\t\t          "train",\n'
                             '\t\t          "testing",\n'
                             '\t\t          "validation"\n'
                             "\t\t     ],\n"
                             '\t\t     "deviation_mse": [\n'
                             '\t\t          "0.173461",\n'
                             '\t\t          "0.289545",\n'
                             '\t\t          "0.297848"\n'
                             "\t\t     ],\n"
                             '\t\t     "value_mse": [\n'
                             '\t\t          "0.421601",\n'
                             '\t\t          "0.67528",\n'
                             '\t\t          "0.671502"\n'
                             "\t\t     ]\n"
                             "\t\t}")

            stdout = logger.logger.handlers[0].stream.getvalue()
            self.assertIn(expected_tsv, stdout)
            self.assertIn(expected_csv, stdout)
            self.assertIn(expected_txt, stdout)
            self.assertIn(expected_json, stdout)