From 487ca898853d4427056d17153b1ba9afb1ccfa1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Thu, 8 Feb 2024 11:20:59 +0100 Subject: [PATCH] chore: add missing test fixture and changelog entry We somehow forgot to include these files in a previous commit... --- .../20240130_123351_regis_fix_save_on_plugins.md | 2 ++ tests/test_plugins.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 changelog.d/20240130_123351_regis_fix_save_on_plugins.md create mode 100644 tests/test_plugins.py diff --git a/changelog.d/20240130_123351_regis_fix_save_on_plugins.md b/changelog.d/20240130_123351_regis_fix_save_on_plugins.md new file mode 100644 index 0000000..164dd81 --- /dev/null +++ b/changelog.d/20240130_123351_regis_fix_save_on_plugins.md @@ -0,0 +1,2 @@ +- [Bugfix] Actually update the environment on `tutor plugins enable ...`. (by @regisb) +- [Feature] Introduce a `tutor.hooks.lru_cache` decorator that is automatically cleared whenever a plugin is loaded or unloaded. This is useful, in particular when a plugin implements a costly function that depends on tutor hooks. (by @regisb) diff --git a/tests/test_plugins.py b/tests/test_plugins.py new file mode 100644 index 0000000..aa6375e --- /dev/null +++ b/tests/test_plugins.py @@ -0,0 +1,16 @@ +from __future__ import annotations + +from tests.helpers import PluginsTestCase +from tutor import hooks, plugins + + +class PluginsTests(PluginsTestCase): + def test_env_patches_updated_on_new_plugin(self) -> None: + self.assertEqual([], list(plugins.iter_patches("mypatch"))) + + hooks.Filters.ENV_PATCHES.add_item(("mypatch", "hello!")) + + # env patches cache should be cleared on new plugin + hooks.Actions.PLUGIN_LOADED.do("dummyplugin") + + self.assertEqual(["hello!"], list(plugins.iter_patches("mypatch")))