diff options
| author | Bouke Haarsma <bouke@webatoom.nl> | 2013-11-01 21:15:41 +0100 |
|---|---|---|
| committer | Baptiste Mispelon <bmispelon@gmail.com> | 2013-11-11 08:53:09 +0100 |
| commit | 9b7455e918a437c3db91e88dcbf6d9c93fef96f8 (patch) | |
| tree | 4cda7466ec20e5255633e7447eaa03ad5450bf24 /tests/staticfiles_tests | |
| parent | 6c5f5b9a414b8bdfafc45db5710acf200cca9885 (diff) | |
Fixed #21351 -- Replaced memoize with Python's lru_cache.
Replaced the custom, untested memoize with a similar decorator from Python's
3.2 stdlib. Although some minor performance degradation (see ticket), it is
expected that in the long run lru_cache will outperform memoize once it is
implemented in C.
Thanks to EvilDMP for the report and Baptiste Mispelon for the idea of
replacing memoize with lru_cache.
Diffstat (limited to 'tests/staticfiles_tests')
| -rw-r--r-- | tests/staticfiles_tests/tests.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/tests/staticfiles_tests/tests.py b/tests/staticfiles_tests/tests.py index 463ab47030..39ce49817c 100644 --- a/tests/staticfiles_tests/tests.py +++ b/tests/staticfiles_tests/tests.py @@ -55,7 +55,7 @@ class BaseStaticFilesTestCase(object): storage.staticfiles_storage._wrapped = empty # Clear the cached staticfile finders, so they are reinitialized every # run and pick up changes in settings.STATICFILES_DIRS. - finders._finders.clear() + finders.get_finder.cache_clear() testfiles_path = os.path.join(TEST_ROOT, 'apps', 'test', 'static', 'test') # To make sure SVN doesn't hangs itself with the non-ASCII characters @@ -561,7 +561,7 @@ class TestCollectionCachedStorage(BaseCollectionTestCase, Test that post_processing indicates the origin of the error when it fails. Regression test for #18986. """ - finders._finders.clear() + finders.get_finder.cache_clear() err = six.StringIO() with self.assertRaises(Exception): call_command('collectstatic', interactive=False, verbosity=0, stderr=err) @@ -756,6 +756,15 @@ class TestMiscFinder(TestCase): self.assertRaises(ImproperlyConfigured, finders.get_finder, 'foo.bar.FooBarFinder') + def test_cache(self): + finders.get_finder.cache_clear() + for n in range(10): + finders.get_finder( + 'django.contrib.staticfiles.finders.FileSystemFinder') + cache_info = finders.get_finder.cache_info() + self.assertEqual(cache_info.hits, 9) + self.assertEqual(cache_info.currsize, 1) + @override_settings(STATICFILES_DIRS='a string') def test_non_tuple_raises_exception(self): """ |
