Skip to content

Commit

Permalink
Merge pull request #120 from madeline-scyphers/testing/add-doctest
Browse files Browse the repository at this point in the history
add doctest to invoke test, more tests to come
  • Loading branch information
madeline-scyphers authored Jul 12, 2023
2 parents 78bf53c + 4a7f2fe commit 4015fa9
Show file tree
Hide file tree
Showing 6 changed files with 3,322 additions and 2,199 deletions.
12 changes: 6 additions & 6 deletions boa/wrappers/base_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,13 +468,13 @@ def fetch_trial_data(self, trial: BaseTrial, metric_properties: dict, metric_nam
>>> def func_a(array):
... return np.mean(np.exp(array))
...
... def func_b(array):
>>> def func_b(array):
... return np.exp(np.mean(array))
...
... funcs = {func_a.__name__: func_a, func_b.__name__: func_b}
...
... def fetch_trial_data(self, trial, metric_properties, metric_name, *args, **kwargs):
>>> funcs = {func_a.__name__: func_a, func_b.__name__: func_b}
>>> def fetch_trial_data(self, trial, metric_properties, metric_name, *args, **kwargs):
... # we define in our config the names of functions to associate with certain metrics
... # and look them up at run time
... return {"a": funcs[metric_properties[metric_name]["function"]](trial.arm.parameters)}
Expand Down
38 changes: 19 additions & 19 deletions boa/wrappers/wrapper_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,21 @@ def cd_and_cd_back(path: PathLike = None):
Examples
========
>>> starting_dir = os.getcwd()
... with cd_and_cd_back():
>>> with cd_and_cd_back():
... # with do some things that change the directory
... os.chdir("..")
... # When we exit the context manager (dedent) we go back to the starting directory
... ending_dir = os.getcwd()
... assert starting_dir == ending_dir
>>> ending_dir = os.getcwd()
>>> assert starting_dir == ending_dir
>>> starting_dir = os.getcwd()
... path_to_change_to = ".."
... with cd_and_cd_back(path=path_to_change_to):
>>> path_to_change_to = ".."
>>> with cd_and_cd_back(path=path_to_change_to):
... # with do some things inside the context manager
... ...
... pass
... # When we exit the context manager (dedent) we go back to the starting directory
... ending_dir = os.getcwd()
... assert starting_dir == ending_dir
>>> ending_dir = os.getcwd()
>>> assert starting_dir == ending_dir
"""
cwd = os.getcwd()
Expand All @@ -101,23 +101,23 @@ def cd_and_cd_back_dec(path: PathLike = None):
Examples
========
>>> @cd_and_cd_back_dec
>>> @cd_and_cd_back_dec()
... def foo():
... os.chdir("..")
...
... starting_dir = os.getcwd()
... foo()
... ending_dir = os.getcwd()
... assert starting_dir == ending_dir
>>> starting_dir = os.getcwd()
>>> foo()
>>> ending_dir = os.getcwd()
>>> assert starting_dir == ending_dir
>>> @cd_and_cd_back_dec(path="..")
... def bar():
... os.chdir("..")
...
... starting_dir = os.getcwd()
... bar()
... ending_dir = os.getcwd()
... assert starting_dir == ending_dir
>>> starting_dir = os.getcwd()
>>> bar()
>>> ending_dir = os.getcwd()
>>> assert starting_dir == ending_dir
"""

Expand Down
Loading

0 comments on commit 4015fa9

Please sign in to comment.