Skip to content

Commit

Permalink
Merge pull request #235 from scottclowe/tst_npil-verb
Browse files Browse the repository at this point in the history
TST: Test neuropil.separate verbosity
  • Loading branch information
scottclowe committed Jul 10, 2021
2 parents 17f1cd3 + 4233521 commit 57a7c80
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions fissa/tests/test_neuropil.py
Expand Up @@ -41,10 +41,23 @@ def run_method(self, method, expected_converged=None, **kwargs):
# If specified, assert that the result is as expected
if expected_converged is not None:
self.assert_equal(convergence["converged"], expected_converged)
return convergence["converged"]

def test_method(self):
self.run_method(self.method, expected_converged=True, max_tries=1)

def test_method_loud(self):
capture_pre = self.capsys.readouterr() # Clear stdout
self.run_method(self.method, expected_converged=True, max_tries=1, verbosity=1)
capture_post = self.recapsys(capture_pre) # Capture and then re-output
self.assertTrue("converged after" in capture_post.out)

def test_method_quiet(self):
capture_pre = self.capsys.readouterr() # Clear stdout
self.run_method(self.method, expected_converged=True, max_tries=1, verbosity=0)
capture_post = self.recapsys(capture_pre) # Capture and then re-output
self.assert_equal(capture_post.out, "")

def test_reduce_dim(self):
self.run_method(self.method, expected_converged=True, max_tries=1, n=2)

Expand All @@ -56,10 +69,28 @@ def test_manual_seed(self):
random_state=0,
)

def test_retry(self):
def test_retry_loud(self):
capture_pre = self.capsys.readouterr() # Clear stdout
with warnings.catch_warnings():
warnings.simplefilter("ignore")
converged = self.run_method(
self.method, max_iter=1, max_tries=3, verbosity=1
)
capture_post = self.recapsys(capture_pre) # Capture and then re-output
if not converged:
self.assertTrue("Attempt 1 failed to converge at " in capture_post.out)
self.assertTrue("Trying a new random state." in capture_post.out)
self.assertTrue(
"aximum number of allowed tries reached" in capture_post.out
)

def test_retry_quiet(self):
capture_pre = self.capsys.readouterr() # Clear stdout
with warnings.catch_warnings():
warnings.simplefilter("ignore")
self.run_method(self.method, max_iter=1, max_tries=3)
self.run_method(self.method, max_iter=1, max_tries=3, verbosity=0)
capture_post = self.recapsys(capture_pre) # Capture and then re-output
self.assert_equal(capture_post.out, "")


class TestNeuropilNMF(BaseTestCase, NeuropilMixin):
Expand Down

0 comments on commit 57a7c80

Please sign in to comment.