-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change clear_cache method to work with table_tree (#213)
* Change clear_cache method to work with table_tree The table_tree cannot be removed as an attribute as it is a property. Setting the _table_tree value to its default of None will force, any call to table_tree to recompute the table_tree cache * Update pre-commit and move flake8 repo to github * Set Table Cached properties as a list and test that all belong are cached properties * Add deleter to table tree property to make it work with delattr * Add docstring to test * Treat table tree as a non cache property (because it is not) * Empty-Commit * Ignore typing errors on Python 3.10 On Python 3.10 the logger has defined the extra as optional. * Set assertions to validate values is not None
- Loading branch information
Showing
3 changed files
with
47 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from cached_property import cached_property | ||
|
||
from widgetastic.widget import Table | ||
from widgetastic.widget import View | ||
|
||
|
||
def test_table_cached_properties(): | ||
"""Cached properties are defined as such""" | ||
for item in Table._CACHED_PROPERTIES: | ||
attribute = getattr(Table, item) | ||
assert isinstance(attribute, cached_property) | ||
|
||
|
||
def test_table_clear_cache(browser): | ||
class TestForm(View): | ||
table = Table("#rowcolspan_table") | ||
|
||
view = TestForm(browser) | ||
table = view.table | ||
|
||
# invoke properties | ||
for item in Table._CACHED_PROPERTIES: | ||
getattr(table, item) | ||
tree = table.table_tree | ||
assert tree is not None, "If the table has not row or col span it won't have a tree" | ||
|
||
table.clear_cache() | ||
|
||
for item in Table._CACHED_PROPERTIES: | ||
assert item not in table.__dict__ | ||
assert table._table_tree is None |