|
27 | 27 | equationFromString, |
28 | 28 | ) |
29 | 29 |
|
30 | | -from .utils import capturestdout |
31 | | - |
32 | 30 | # ---------------------------------------------------------------------------- |
33 | 31 |
|
34 | 32 |
|
@@ -519,52 +517,57 @@ def test_releaseOldEquations(self): |
519 | 517 | self.assertEqual(0, len(self.m._eqfactory.equations)) |
520 | 518 | return |
521 | 519 |
|
522 | | - def test_show(self): |
523 | | - """Verify output from the show function.""" |
524 | | - |
525 | | - def capture_show(*args, **kwargs): |
526 | | - rv = capturestdout(self.m.show, *args, **kwargs) |
527 | | - return rv |
528 | | - |
529 | | - self.assertEqual("", capture_show()) |
530 | | - self.m._newParameter("x", 1) |
531 | | - self.m._newParameter("y", 2) |
532 | | - out1 = capture_show() |
533 | | - lines1 = out1.strip().split("\n") |
534 | | - self.assertEqual(4, len(lines1)) |
535 | | - self.assertTrue("Parameters" in lines1) |
536 | | - self.assertFalse("Constraints" in lines1) |
537 | | - self.assertFalse("Restraints" in lines1) |
538 | | - self.m._newParameter("z", 7) |
539 | | - self.m.constrain("y", "3 * z") |
540 | | - out2 = capture_show() |
541 | | - lines2 = out2.strip().split("\n") |
542 | | - self.assertEqual(9, len(lines2)) |
543 | | - self.assertTrue("Parameters" in lines2) |
544 | | - self.assertTrue("Constraints" in lines2) |
545 | | - self.assertFalse("Restraints" in lines2) |
546 | | - self.m.restrain("z", lb=2, ub=3, sig=0.001) |
547 | | - out3 = capture_show() |
548 | | - lines3 = out3.strip().split("\n") |
549 | | - self.assertEqual(13, len(lines3)) |
550 | | - self.assertTrue("Parameters" in lines3) |
551 | | - self.assertTrue("Constraints" in lines3) |
552 | | - self.assertTrue("Restraints" in lines3) |
553 | | - out4 = capture_show(pattern="x") |
554 | | - lines4 = out4.strip().split("\n") |
555 | | - self.assertEqual(9, len(lines4)) |
556 | | - out5 = capture_show(pattern="^") |
557 | | - self.assertEqual(out3, out5) |
558 | | - # check output with another level of hierarchy |
559 | | - self.m._addObject(RecipeOrganizer("foo"), self.m._containers) |
560 | | - self.m.foo._newParameter("bar", 13) |
561 | | - out6 = capture_show() |
562 | | - self.assertTrue("foo.bar" in out6) |
563 | | - # filter out foo.bar |
564 | | - out7 = capture_show("^(?!foo).") |
565 | | - self.assertFalse("foo.bar" in out7) |
566 | | - self.assertEqual(out3, out7) |
567 | | - return |
| 520 | + |
| 521 | +def test_show(capturestdout): |
| 522 | + """Verify output from the show function.""" |
| 523 | + organizer = RecipeOrganizer("test") |
| 524 | + # Add a managed container so we can do more in-depth tests. |
| 525 | + organizer._containers = {} |
| 526 | + organizer._manage(organizer._containers) |
| 527 | + |
| 528 | + def capture_show(*args, **kwargs): |
| 529 | + rv = capturestdout(organizer.show, *args, **kwargs) |
| 530 | + return rv |
| 531 | + |
| 532 | + assert "" == capture_show() |
| 533 | + organizer._newParameter("x", 1) |
| 534 | + organizer._newParameter("y", 2) |
| 535 | + out1 = capture_show() |
| 536 | + lines1 = out1.strip().split("\n") |
| 537 | + assert 4 == len(lines1) |
| 538 | + assert "Parameters" in lines1 |
| 539 | + assert "Constraints" not in lines1 |
| 540 | + assert "Restraints" not in lines1 |
| 541 | + organizer._newParameter("z", 7) |
| 542 | + organizer.constrain("y", "3 * z") |
| 543 | + out2 = capture_show() |
| 544 | + lines2 = out2.strip().split("\n") |
| 545 | + assert 9 == len(lines2) |
| 546 | + assert "Parameters" in lines2 |
| 547 | + assert "Constraints" in lines2 |
| 548 | + assert "Restraints" not in lines2 |
| 549 | + organizer.restrain("z", lb=2, ub=3, sig=0.001) |
| 550 | + out3 = capture_show() |
| 551 | + lines3 = out3.strip().split("\n") |
| 552 | + assert 13 == len(lines3) |
| 553 | + assert "Parameters" in lines3 |
| 554 | + assert "Constraints" in lines3 |
| 555 | + assert "Restraints" in lines3 |
| 556 | + out4 = capture_show(pattern="x") |
| 557 | + lines4 = out4.strip().split("\n") |
| 558 | + assert 9 == len(lines4) |
| 559 | + out5 = capture_show(pattern="^") |
| 560 | + assert out3 == out5 |
| 561 | + # check output with another level of hierarchy |
| 562 | + organizer._addObject(RecipeOrganizer("foo"), organizer._containers) |
| 563 | + organizer.foo._newParameter("bar", 13) |
| 564 | + out6 = capture_show() |
| 565 | + assert "foo.bar" in out6 |
| 566 | + # filter out foo.bar |
| 567 | + out7 = capture_show("^(?!foo).") |
| 568 | + assert "foo.bar" not in out7 |
| 569 | + assert out3 == out7 |
| 570 | + return |
568 | 571 |
|
569 | 572 |
|
570 | 573 | # ---------------------------------------------------------------------------- |
|
0 commit comments