From 4241b15cc44e5e66e5f1bf1f42c54469f89dc9f5 Mon Sep 17 00:00:00 2001 From: Joel Hillacre Date: Thu, 30 Jan 2020 16:35:38 -0700 Subject: [PATCH 1/5] update .gitignore re: desired shared .idea files. --- .gitignore | 88 ++++--------------- .../inspectionProfiles/profiles_settings.xml | 7 -- .idea/misc.xml | 10 --- .idea/modules.xml | 8 -- .idea/shy-sentry.iml | 11 --- 5 files changed, 17 insertions(+), 107 deletions(-) delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/shy-sentry.iml diff --git a/.gitignore b/.gitignore index c0d0f7e..eab5d48 100644 --- a/.gitignore +++ b/.gitignore @@ -128,77 +128,23 @@ dmypy.json # Pyre type checker .pyre/ -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf - -# Generated files -.idea/**/contentModel.xml - -# Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml - -# Gradle -.idea/**/gradle.xml -.idea/**/libraries - -# Gradle and Maven with auto-import -# When using Gradle or Maven with auto-import, you should exclude module files, -# since they will be recreated, and may cause churn. Uncomment if using -# auto-import. -# .idea/artifacts -# .idea/compiler.xml -# .idea/jarRepositories.xml -# .idea/modules.xml -# .idea/*.iml -# .idea/modules -# *.iml -# *.ipr - -# CMake -cmake-build-*/ - -# Mongo Explorer plugin -.idea/**/mongoSettings.xml - -# File-based project format -*.iws - -# IntelliJ -out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Cursive Clojure plugin -.idea/replstate.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -# Editor-based Rest Client -.idea/httpRequests - -# Android studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser +### custom JetBrains .gitignore rules. +### Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +## ignore all files +.idea/* + +## except +!.idea/.gitignore + +# know that there is a git repo in the root. +!.idea/vcs.xml + +# enable the watcher task named "Black" by default. +!.idea/watcherTasks.xml + +# have the "Black Scope" scope by default. +!.idea/scopes ### pretenders pids *.pid diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index dd4c951..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index bca969a..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index a4e9169..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/shy-sentry.iml b/.idea/shy-sentry.iml deleted file mode 100644 index f3fb5d7..0000000 --- a/.idea/shy-sentry.iml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file From 6219bce317e0c97a2d1c762eb26b4c5d2b010ef2 Mon Sep 17 00:00:00 2001 From: Jayden Kneller Date: Tue, 18 Feb 2020 11:56:54 -0700 Subject: [PATCH 2/5] remove double pop. --- shy_sentry/shy_sentry.py | 1 - 1 file changed, 1 deletion(-) diff --git a/shy_sentry/shy_sentry.py b/shy_sentry/shy_sentry.py index cc826be..cf2017f 100644 --- a/shy_sentry/shy_sentry.py +++ b/shy_sentry/shy_sentry.py @@ -61,7 +61,6 @@ def init(config_path=None, **kwargs): ) if "integrations" in kwargs: sentry_kwargs["integrations"].extend(kwargs.pop("integrations")) - kwargs.pop("integrations") sentry_kwargs.update(kwargs) patch_sentry() From b42904928d74a1431be7b348d10dd5d7a0efd236 Mon Sep 17 00:00:00 2001 From: Joel Hillacre Date: Tue, 18 Feb 2020 12:15:00 -0700 Subject: [PATCH 3/5] add additional local venvs to gitignore. --- .gitignore | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index eab5d48..8a338ab 100644 --- a/.gitignore +++ b/.gitignore @@ -102,13 +102,13 @@ celerybeat.pid *.sage.py # Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ +.env* +.venv* +env*/ +venv*/ +ENV*/ +env*.bak/ +venv*.bak/ # Spyder project settings .spyderproject From 7f4fddf9bad021dfef1a9aa26489ed2d9c580c7a Mon Sep 17 00:00:00 2001 From: Joel Hillacre Date: Wed, 19 Feb 2020 11:01:12 -0700 Subject: [PATCH 4/5] test the integration handling in our init(). --- shy_sentry/shy_sentry.py | 35 ++++++------- tests/test_scripts/add_integrations.py | 12 +++++ tests/test_scripts/no_default_integrations.py | 31 +++++++++++ tests/test_shy.py | 52 +++++++++++++++++++ 4 files changed, 112 insertions(+), 18 deletions(-) create mode 100644 tests/test_scripts/add_integrations.py create mode 100644 tests/test_scripts/no_default_integrations.py diff --git a/shy_sentry/shy_sentry.py b/shy_sentry/shy_sentry.py index cf2017f..86c5010 100644 --- a/shy_sentry/shy_sentry.py +++ b/shy_sentry/shy_sentry.py @@ -1,10 +1,10 @@ # Copyright (C) 2020 Arrai Innovations Inc. - All Rights Reserved import json +from contextlib import AbstractContextManager from functools import wraps -from typing import ContextManager -from sentry_sdk import init as sentry_sdk_init from sentry_sdk import Hub +from sentry_sdk import init as sentry_sdk_init from sentry_sdk import serializer from sentry_sdk._types import MYPY from sentry_sdk.integrations.argv import ArgvIntegration @@ -30,6 +30,19 @@ def patch_sentry(): serializer.MAX_DATABAG_DEPTH = 20 +def get_our_default_integrations(): + return [ + LoggingIntegration(), + StdlibIntegration(), + ExcepthookIntegration(), + DedupeIntegration(), + AtexitIntegration(callback=default_callback), + ModulesIntegration(), + ArgvIntegration(), + ThreadingIntegration(), + ] + + def init(config_path=None, **kwargs): if not config_path: config_path = "./sentry_config.json" @@ -44,21 +57,7 @@ def init(config_path=None, **kwargs): # if you don't want to do stuff to default integrations, user our modified defaults that make things quiet # otherwise, you are on your own to pass kwargs. if "default_integrations" not in kwargs: - sentry_kwargs.update( - { - "default_integrations": False, - "integrations": [ - LoggingIntegration(), - StdlibIntegration(), - ExcepthookIntegration(), - DedupeIntegration(), - AtexitIntegration(callback=default_callback), - ModulesIntegration(), - ArgvIntegration(), - ThreadingIntegration(), - ], - } - ) + sentry_kwargs.update({"default_integrations": False, "integrations": get_our_default_integrations()}) if "integrations" in kwargs: sentry_kwargs["integrations"].extend(kwargs.pop("integrations")) sentry_kwargs.update(kwargs) @@ -68,7 +67,7 @@ def init(config_path=None, **kwargs): sentry_sdk_init(**sentry_kwargs) -class Guard(ContextManager): +class Guard(AbstractContextManager): def __enter__(self): pass diff --git a/tests/test_scripts/add_integrations.py b/tests/test_scripts/add_integrations.py new file mode 100644 index 0000000..8724b8f --- /dev/null +++ b/tests/test_scripts/add_integrations.py @@ -0,0 +1,12 @@ +# Copyright (C) 2020 Arrai Innovations Inc. - All Rights Reserved +import os +import sys + +from sentry_sdk.integrations.redis import RedisIntegration + +sys.path.append(os.getcwd()) +import shy_sentry # noqa: E402 + + +if __name__ == "__main__": # pragma: no branch + shy_sentry.init(integrations=[RedisIntegration()]) diff --git a/tests/test_scripts/no_default_integrations.py b/tests/test_scripts/no_default_integrations.py new file mode 100644 index 0000000..82843d5 --- /dev/null +++ b/tests/test_scripts/no_default_integrations.py @@ -0,0 +1,31 @@ +# Copyright (C) 2020 Arrai Innovations Inc. - All Rights Reserved +import os +import sys + +from sentry_sdk.integrations.argv import ArgvIntegration +from sentry_sdk.integrations.atexit import AtexitIntegration +from sentry_sdk.integrations.dedupe import DedupeIntegration +from sentry_sdk.integrations.excepthook import ExcepthookIntegration +from sentry_sdk.integrations.modules import ModulesIntegration +from sentry_sdk.integrations.redis import RedisIntegration +from sentry_sdk.integrations.stdlib import StdlibIntegration +from sentry_sdk.integrations.threading import ThreadingIntegration + +sys.path.append(os.getcwd()) +import shy_sentry # noqa: E402 + + +if __name__ == "__main__": # pragma: no branch + shy_sentry.init( + integrations=[ + StdlibIntegration(), + ExcepthookIntegration(), + DedupeIntegration(), + AtexitIntegration(callback=shy_sentry.shy_sentry.default_callback), + ModulesIntegration(), + ArgvIntegration(), + ThreadingIntegration(), + RedisIntegration(), + ], + default_integrations=False, + ) diff --git a/tests/test_shy.py b/tests/test_shy.py index 3c11df4..d302518 100644 --- a/tests/test_shy.py +++ b/tests/test_shy.py @@ -1,8 +1,10 @@ # Copyright (C) 2020 Arrai Innovations Inc. - All Rights Reserved import os import subprocess +from contextlib import AbstractContextManager from time import sleep from unittest import TestCase +from unittest.mock import patch import psutil from pretenders.client.http import HTTPMock @@ -109,3 +111,53 @@ def test_cwd_config(self): self.do_test("./tests/test_scripts/cwd_config.py") finally: os.unlink("./sentry_config.json") + + +@patch("shy_sentry.shy_sentry.sentry_sdk_init") +class MockSentrySdkTestCase(TestCase): + def test_add_integrations(self, mocked_sentry_sdk_init): + from shy_sentry import init + from shy_sentry.shy_sentry import get_our_default_integrations + from sentry_sdk.integrations.redis import RedisIntegration + + default_integrations = get_our_default_integrations() + integrations = [RedisIntegration()] + init(integrations=integrations, config_path="./tests/test_scripts/sentry_config.json") + mocked_sentry_sdk_init.assert_called_once() + self.assertEqual(len(mocked_sentry_sdk_init.call_args_list[0]), 2) + call_args, call_kwargs = mocked_sentry_sdk_init.call_args_list[0] + self.assertTupleEqual(call_args, ()) + self.assertSetEqual( + {"default_integrations", "dsn", "environment", "integrations", "release"}, set(call_kwargs.keys()), + ) + self.assertEqual(call_kwargs["default_integrations"], False) + self.assertEqual(call_kwargs["dsn"], "http://client_key@localhost:8888/mockhttp/mock_sentry/123456") + self.assertEqual(call_kwargs["environment"], "dev") + self.assertEqual(call_kwargs["release"], "project:branch@version") + self.assertSetEqual( + {x.__class__ for x in call_kwargs["integrations"]}, + {x.__class__ for x in default_integrations + integrations}, + ) + + def test_no_default_integrations(self, mocked_sentry_sdk_init): + from shy_sentry import init + from sentry_sdk.integrations.redis import RedisIntegration + + integrations = [RedisIntegration()] + init( + default_integrations=False, integrations=integrations, config_path="./tests/test_scripts/sentry_config.json" + ) + mocked_sentry_sdk_init.assert_called_once() + self.assertEqual(len(mocked_sentry_sdk_init.call_args_list[0]), 2) + call_args, call_kwargs = mocked_sentry_sdk_init.call_args_list[0] + self.assertTupleEqual(call_args, ()) + self.assertSetEqual( + {"default_integrations", "dsn", "environment", "integrations", "release"}, set(call_kwargs.keys()), + ) + self.assertEqual(call_kwargs["default_integrations"], False) + self.assertEqual(call_kwargs["dsn"], "http://client_key@localhost:8888/mockhttp/mock_sentry/123456") + self.assertEqual(call_kwargs["environment"], "dev") + self.assertEqual(call_kwargs["release"], "project:branch@version") + self.assertSetEqual( + {x.__class__ for x in call_kwargs["integrations"]}, {x.__class__ for x in integrations}, + ) From 989b7ff9887684311ff8b2248c127abeb418cd28 Mon Sep 17 00:00:00 2001 From: Joel Hillacre Date: Wed, 19 Feb 2020 11:02:05 -0700 Subject: [PATCH 5/5] bump --- shy_sentry/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shy_sentry/__init__.py b/shy_sentry/__init__.py index 988c6ee..dd35f07 100644 --- a/shy_sentry/__init__.py +++ b/shy_sentry/__init__.py @@ -1,5 +1,5 @@ # Copyright (C) 2020 Arrai Innovations Inc. - All Rights Reserved -__version__ = "1.1.0" +__version__ = "1.1.1" try: from .shy_sentry import init, Guard