Skip to content

Commit

Permalink
Clean up utility functions. (#597)
Browse files Browse the repository at this point in the history
* Clean up utility functions.

* Add missing test case for dotted keys function where values are empty dicts.
  • Loading branch information
bdice authored and vyasr committed Oct 30, 2022
1 parent 5685b55 commit 4a7b549
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
3 changes: 1 addition & 2 deletions signac/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1696,8 +1696,7 @@ def main():

parser_update_cache = subparsers.add_parser(
"update-cache",
description="""Use this command to update the project's persistent state point cache.
This feature is still experimental and may be removed in future versions.""",
description="Use this command to update the project's persistent state point cache.",
)
parser_update_cache.set_defaults(func=main_update_cache)

Expand Down
4 changes: 2 additions & 2 deletions signac/contrib/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from .indexing import _SignacProjectCrawler
from .job import Job
from .schema import ProjectSchema, _collect_by_type
from .utility import _mkdir_p, _nested_dicts_to_dotted_keys, split_and_print_progress
from .utility import _mkdir_p, _nested_dicts_to_dotted_keys, _split_and_print_progress

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -1810,7 +1810,7 @@ def _update_in_memory_cache(self):
def _add(_id):
self._sp_cache[_id] = self._get_statepoint_from_workspace(_id)

to_add_chunks = split_and_print_progress(
to_add_chunks = _split_and_print_progress(
iterable=list(to_add),
num_chunks=max(1, min(100, int(len(to_add) / 1000))),
write=logger.info,
Expand Down
4 changes: 2 additions & 2 deletions signac/contrib/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
logger = logging.getLogger(__name__)


def query_yes_no(question, default="yes"):
def query_yes_no(question, default="yes"): # pragma: no cover
"""Ask a yes/no question via input() and return their answer.
"question" is a string that is presented to the user.
Expand Down Expand Up @@ -146,7 +146,7 @@ def _mkdir_p(path):
os.makedirs(path, exist_ok=True)


def split_and_print_progress(iterable, num_chunks=10, write=None, desc="Progress: "):
def _split_and_print_progress(iterable, num_chunks=10, write=None, desc="Progress: "):
"""Split the progress and prints it.
Parameters
Expand Down
22 changes: 16 additions & 6 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,9 @@ def test_schema(self):
for i in range(10):
self.project.open_job(
{
"const": 0,
"const1": 0,
"const2": {"const3": 0},
"const4": {},
"a": i,
"b": {"b2": i},
"c": [i if i % 2 else None, 0, 0],
Expand All @@ -828,8 +829,18 @@ def test_schema(self):
).init()

s = self.project.detect_schema()
assert len(s) == 9
for k in "const", "const2.const3", "a", "b.b2", "c", "d", "e.e2", "f.f2":
assert len(s) == 10
for k in (
"const1",
"const2.const3",
"const4",
"a",
"b.b2",
"c",
"d",
"e.e2",
"f.f2",
):
assert k in s
if "." in k:
with pytest.warns(FutureWarning):
Expand All @@ -843,10 +854,9 @@ def test_schema(self):
assert s.format() == str(s)
s = self.project.detect_schema(exclude_const=True)
assert len(s) == 7
assert "const" not in s
with pytest.warns(FutureWarning):
assert ("const2", "const3") not in s
assert "const1" not in s
assert "const2.const3" not in s
assert "const4" not in s
assert type not in s["e"]

def test_schema_subset(self):
Expand Down

0 comments on commit 4a7b549

Please sign in to comment.