Example #1
0
class DisplayTest(TestCase):
    def setUp(self):
        self.project = Arguments(["test.mad", "25"])
        self.output = StringIO()
        self.display = Display(self.output)

    def test_boot_up(self):
        self.display.boot_up()
        self._verify_output(MAD_VERSION)

    def test_simulation_started(self):
        self.display.model_loaded(self.project)
        self._verify_output(self.project._file_name)

    def test_simulation_update(self):
        self.display.update(20, 100)
        self._verify_output("20.00 %")

    def test_simulation_complete(self):
        self.display.simulation_complete(self.project)
        self._verify_output(self.project._output_directory)

    def _verify_output(self, expected_pattern):
        output = self.output.getvalue()
        match = search(escape(expected_pattern), output, IGNORECASE)
        self.assertIsNotNone(match,
                             msg="Could not find '%s' in output '%s'" %
                             (expected_pattern, output))

    def _make_fake_simulation(self):
        simulation = MagicMock()
        simulation.run_until = MagicMock()

        def run_simulation(limit, display):
            for i in range(1, 6):
                display.update(i * 5, limit)

        simulation.run_until.side_effect = run_simulation
        return simulation
Example #2
0
class DisplayTest(TestCase):

    def setUp(self):
        self.project = Arguments(["test.mad", "25"])
        self.output = StringIO()
        self.display = Display(self.output)

    def test_boot_up(self):
        self.display.boot_up()
        self._verify_output(MAD_VERSION)

    def test_simulation_started(self):
        self.display.model_loaded(self.project)
        self._verify_output(self.project._file_name)

    def test_simulation_update(self):
        self.display.update(20, 100)
        self._verify_output("20.00 %")

    def test_simulation_complete(self):
        self.display.simulation_complete(self.project)
        self._verify_output(self.project._output_directory)

    def _verify_output(self, expected_pattern):
        output = self.output.getvalue()
        match = search(escape(expected_pattern), output, IGNORECASE)
        self.assertIsNotNone(match, msg="Could not find '%s' in output '%s'" % (expected_pattern, output))

    def _make_fake_simulation(self):
        simulation = MagicMock()
        simulation.run_until = MagicMock()

        def run_simulation(limit, display):
            for i in range(1,6):
                display.update(i*5, limit)

        simulation.run_until.side_effect = run_simulation
        return simulation