Exemplo n.º 1
0
    def test_patch_modules_from_env(self):
        """
        DATADOG_PATCH_MODULES overrides the defaults for patch_all()
        """
        from ddtrace.bootstrap.sitecustomize import EXTRA_PATCHED_MODULES
        from ddtrace.bootstrap.sitecustomize import update_patched_modules

        orig = EXTRA_PATCHED_MODULES.copy()

        # empty / malformed strings are no-ops
        with self.override_env(dict(DATADOG_PATCH_MODULES="")):
            update_patched_modules()
            assert orig == EXTRA_PATCHED_MODULES

        with self.override_env(dict(DATADOG_PATCH_MODULES=":")):
            update_patched_modules()
            assert orig == EXTRA_PATCHED_MODULES

        with self.override_env(dict(DATADOG_PATCH_MODULES=",")):
            update_patched_modules()
            assert orig == EXTRA_PATCHED_MODULES

        with self.override_env(dict(DATADOG_PATCH_MODULES=",:")):
            update_patched_modules()
            assert orig == EXTRA_PATCHED_MODULES

        # overrides work in either direction
        with self.override_env(dict(DATADOG_PATCH_MODULES="django:false")):
            update_patched_modules()
            assert EXTRA_PATCHED_MODULES["django"] is False

        with self.override_env(dict(DATADOG_PATCH_MODULES="boto:true")):
            update_patched_modules()
            assert EXTRA_PATCHED_MODULES["boto"] is True

        with self.override_env(
                dict(DATADOG_PATCH_MODULES="django:true,boto:false")):
            update_patched_modules()
            assert EXTRA_PATCHED_MODULES["boto"] is False
            assert EXTRA_PATCHED_MODULES["django"] is True

        with self.override_env(
                dict(DATADOG_PATCH_MODULES="django:false,boto:true")):
            update_patched_modules()
            assert EXTRA_PATCHED_MODULES["boto"] is True
            assert EXTRA_PATCHED_MODULES["django"] is False
Exemplo n.º 2
0
    def test_patch_modules_from_env(self):
        """
        DATADOG_PATCH_MODULES overrides the defaults for patch_all()
        """
        from ddtrace.bootstrap.sitecustomize import EXTRA_PATCHED_MODULES, update_patched_modules
        orig = EXTRA_PATCHED_MODULES.copy()

        # empty / malformed strings are no-ops
        os.environ["DATADOG_PATCH_MODULES"] = ""
        update_patched_modules()
        assert orig == EXTRA_PATCHED_MODULES

        os.environ["DATADOG_PATCH_MODULES"] = ":"
        update_patched_modules()
        assert orig == EXTRA_PATCHED_MODULES

        os.environ["DATADOG_PATCH_MODULES"] = ","
        update_patched_modules()
        assert orig == EXTRA_PATCHED_MODULES

        os.environ["DATADOG_PATCH_MODULES"] = ",:"
        update_patched_modules()
        assert orig == EXTRA_PATCHED_MODULES

        # overrides work in either direction
        os.environ["DATADOG_PATCH_MODULES"] = "django:false"
        update_patched_modules()
        assert EXTRA_PATCHED_MODULES["django"] == False

        os.environ["DATADOG_PATCH_MODULES"] = "boto:true"
        update_patched_modules()
        assert EXTRA_PATCHED_MODULES["boto"] == True

        os.environ["DATADOG_PATCH_MODULES"] = "django:true,boto:false"
        update_patched_modules()
        assert EXTRA_PATCHED_MODULES["boto"] == False
        assert EXTRA_PATCHED_MODULES["django"] == True

        os.environ["DATADOG_PATCH_MODULES"] = "django:false,boto:true"
        update_patched_modules()
        assert EXTRA_PATCHED_MODULES["boto"] == True
        assert EXTRA_PATCHED_MODULES["django"] == False
Exemplo n.º 3
0
    def test_patch_modules_from_env(self):
        """
        DATADOG_PATCH_MODULES overrides the defaults for patch_all()
        """
        from ddtrace.bootstrap.sitecustomize import EXTRA_PATCHED_MODULES, update_patched_modules
        orig = EXTRA_PATCHED_MODULES.copy()

        # empty / malformed strings are no-ops
        os.environ["DATADOG_PATCH_MODULES"] = ""
        update_patched_modules()
        assert orig == EXTRA_PATCHED_MODULES

        os.environ["DATADOG_PATCH_MODULES"] = ":"
        update_patched_modules()
        assert orig == EXTRA_PATCHED_MODULES

        os.environ["DATADOG_PATCH_MODULES"] = ","
        update_patched_modules()
        assert orig == EXTRA_PATCHED_MODULES

        os.environ["DATADOG_PATCH_MODULES"] = ",:"
        update_patched_modules()
        assert orig == EXTRA_PATCHED_MODULES

        # overrides work in either direction
        os.environ["DATADOG_PATCH_MODULES"] = "django:false"
        update_patched_modules()
        assert EXTRA_PATCHED_MODULES["django"] == False

        os.environ["DATADOG_PATCH_MODULES"] = "boto:true"
        update_patched_modules()
        assert EXTRA_PATCHED_MODULES["boto"] == True

        os.environ["DATADOG_PATCH_MODULES"] = "django:true,boto:false"
        update_patched_modules()
        assert EXTRA_PATCHED_MODULES["boto"] == False
        assert EXTRA_PATCHED_MODULES["django"] == True

        os.environ["DATADOG_PATCH_MODULES"] = "django:false,boto:true"
        update_patched_modules()
        assert EXTRA_PATCHED_MODULES["boto"] == True
        assert EXTRA_PATCHED_MODULES["django"] == False