Skip to content
Permalink
Browse files

Add function to clear Houdini caches.

  • Loading branch information
captainhammy committed Oct 23, 2019
1 parent b69ba38 commit 310e1cc2a51080d283b4e956d30e03fea551d49f
Showing with 78 additions and 2 deletions.
  1. +1 −2 bin/run_tests.py
  2. +21 −0 python/ht/inline/api.py
  3. +31 −0 python/ht/inline/lib.py
  4. +25 −0 tests/inline/test_api.py
@@ -1,5 +1,4 @@
"""Discover and run unittests, with coverage."""

"""Discover and run unit tests, with coverage."""

# =============================================================================
# IMPORTS
@@ -64,6 +64,27 @@ def _assert_prim_vertex_index(prim, index):
# FUNCTIONS
# =============================================================================

def clear_caches(cache_names=None):
"""Clear internal Houdini caches.
Cache names match those displayed in the Cache Manager window.
If cache_names is None then all caches will be cleared.
:param cache_names: Optional list of caches to clear.
:type cache_names: list(str)
:return:
"""
# If the value is None then we will pass an empty string to clear all the
# caches.
if cache_names is None:
cache_names = [""]

for cache_name in cache_names:
_cpp_methods.clearCacheByName(cache_name)


def is_rendering():
"""Check if Houdini is rendering or not.
@@ -18,6 +18,37 @@
# =============================================================================

_FUNCTION_SOURCES = [
"""
void clearCacheByName(const char* cache_name)
{
UT_Cache *cache;
UT_ValArray<UT_Cache *> caches;
caches = UT_Cache::utGetCacheList();
for (int i=0; i<caches.entries(); ++i)
{
// Get the current cache.
cache = caches(i);
// Check for not empty string.
if (UT_String(cache_name).length())
{
// Check if the name to clear matches this cache name exactly.
if (strcmp(cache->utGetCacheName(), cache_name) == 0)
{
cache->utClearCache();
}
}
// Empty string means clear all caches
else {
cache->utClearCache();
}
}
}
""",

"""
FloatArray
point_instance_transform(const GU_Detail *gdp, int ptnum)
@@ -57,6 +57,31 @@ def test_valid(self, mocker):

# Functions

class Test_clear_caches(object):
"""Test ht.inline.api.clear_caches."""

def test_default_none(self, mocker):
"""Test with the default arg of None."""
mock_clear = mocker.patch("ht.inline.api._cpp_methods.clearCacheByName")

api.clear_caches()

mock_clear.assert_called_with("")

def test_args(self, mocker):
"""Test with the default arg of None."""
mock_clear = mocker.patch("ht.inline.api._cpp_methods.clearCacheByName")

mock_name1 = mocker.MagicMock(spec=str)
mock_name2 = mocker.MagicMock(spec=str)

api.clear_caches([mock_name1, mock_name2])

mock_clear.assert_has_calls(
[mocker.call(mock_name1), mocker.call(mock_name2)]
)


def test_is_rendering(mocker):
"""Test ht.inline.api.is_rendering."""
mock_rendering = mocker.patch("ht.inline.api._cpp_methods.isRendering")

0 comments on commit 310e1cc

Please sign in to comment.
You can’t perform that action at this time.