예제 #1
0
파일: test_logger.py 프로젝트: rpip/dvc
    def setUp(self):
        logger.logger.handlers = [
            logger.logging.StreamHandler(),
            logger.logging.StreamHandler(),
        ]
        reset_logger_standard_output()
        reset_logger_error_output()
        logger.set_default_level()

        self.consoleColorRemover = ConsoleFontColorsRemover()
        self.consoleColorRemover.__enter__()
예제 #2
0
    def setUp(self):
        logger.logger.handlers = [
            logger.logging.StreamHandler(),
            logger.logging.StreamHandler(),
        ]
        logger.logger.handlers[0].stream = StringIO()
        logger.logger.handlers[1].stream = StringIO()
        logger.set_default_level()

        self.consoleColorRemover = ConsoleFontColorsRemover()
        self.consoleColorRemover.__enter__()
예제 #3
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)
예제 #4
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())
예제 #5
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(),
            )
예제 #6
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(),
            )
예제 #7
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()
예제 #8
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(),
            )
예제 #9
0
 def test(self):
     with ConsoleFontColorsRemover():
         self._test()
예제 #10
0
class TestLogger(TestCase):
    handlers = logger.logger.handlers

    def setUp(self):
        logger.logger.handlers = [
            logger.logging.StreamHandler(),
            logger.logging.StreamHandler(),
        ]
        logger.logger.handlers[0].stream = StringIO()
        logger.logger.handlers[1].stream = StringIO()
        logger.set_default_level()

        self.consoleColorRemover = ConsoleFontColorsRemover()
        self.consoleColorRemover.__enter__()

    def tearDown(self):
        logger.logger.handlers = self.handlers
        logger.be_verbose()
        self.consoleColorRemover.__exit__()

    @property
    def stdout(self):
        return logger.logger.handlers[0].stream.getvalue()

    @property
    def stderr(self):
        return logger.logger.handlers[1].stream.getvalue()

    def test_info(self):
        logger.info("message")

        self.assertEqual(self.stdout, "message\n")

    def test_debug(self):
        with logger.verbose():
            logger.debug("message")

        self.assertEqual(self.stdout, "Debug: message\n")

    def test_warning(self):
        logger.warning("message")

        self.assertEqual(self.stdout, "Warning: message\n")

    def test_error(self):
        logger.error("message")

        output = (
            "Error: message\n"
            "\n"
            "Having any troubles? Hit us up at https://dvc.org/support,"
            " we are always happy to help!\n"
        )

        self.assertEqual(self.stderr, output)

    def test_error_with_exception(self):
        try:
            raise Exception("exception description")
        except Exception:
            logger.error("")

        output = (
            "Error: exception description\n"
            "\n"
            "Having any troubles? Hit us up at https://dvc.org/support,"
            " we are always happy to help!\n"
        )

        self.assertEqual(self.stderr, output)

    def test_error_with_exception_and_message(self):
        try:
            raise Exception("exception description")
        except Exception:
            logger.error("message")

        output = (
            "Error: message - exception description\n"
            "\n"
            "Having any troubles? Hit us up at https://dvc.org/support,"
            " we are always happy to help!\n"
        )

        self.assertEqual(self.stderr, output)

    def test_error_with_chained_exception_and_message(self):
        try:
            raise DvcException("exception", cause=Exception("cause"))
        except Exception:
            logger.error("message")

        output = (
            "Error: message - exception: cause\n"
            "\n"
            "Having any troubles? Hit us up at https://dvc.org/support,"
            " we are always happy to help!\n"
        )

        self.assertEqual(self.stderr, output)

    def test_traceback(self):
        stack_trace1 = "stack_trace1\n"
        stack_trace2 = "stack_trace2\n"
        try:
            exc1 = Exception("exception1")
            exc2 = DvcException("exception2", cause=exc1)
            exc2.cause_tb = stack_trace1
            exc3 = DvcException("exception3", cause=exc2)
            exc3.cause_tb = stack_trace2
            raise exc3
        except Exception:
            stack_trace3 = traceback.format_exc()
            with logger.verbose():
                logger.error("message")

        output = (
            "Error: message - exception3: exception2: exception1\n"
            "{line}\n"
            "{stack_trace1}"
            "\n"
            "{stack_trace2}"
            "\n"
            "{stack_trace3}"
            "{line}\n"
            "\n"
            "Having any troubles? Hit us up at https://dvc.org/support,"
            " we are always happy to help!\n"
        ).format(
            line="-" * 60,
            stack_trace1=stack_trace1,
            stack_trace2=stack_trace2,
            stack_trace3=stack_trace3,
        )

        self.assertEqual(self.stderr, output)

    def test_box(self):
        logger.box("message")

        output = (
            "+-----------------+\n"
            "|                 |\n"
            "|     message     |\n"
            "|                 |\n"
            "+-----------------+\n"
            "\n"
        )

        self.assertEqual(self.stdout, output)

    def test_level(self):
        self.assertEqual(logger.level(), logging.INFO)

    def test_is_verbose(self):
        self.assertFalse(logger.is_verbose())

        with logger.verbose():
            self.assertTrue(logger.is_verbose())

    def test_is_quiet(self):
        self.assertFalse(logger.is_quiet())

        with logger.quiet():
            self.assertFalse(logger.is_verbose())

    def test_cli(self):
        class A(object):
            quiet = True
            verbose = False

        args = A()
        CmdBase.set_loglevel(args)
        self.assertEqual(logger.logger.getEffectiveLevel(), logging.CRITICAL)

        args.quiet = False
        args.verbose = True
        CmdBase.set_loglevel(args)
        self.assertEqual(logger.logger.getEffectiveLevel(), logging.DEBUG)