def main():
    """Run the test."""
    # Create the logger.
    log_file_name = sys.argv[1] if len(sys.argv) > 1 else '-'
    log_to_file = log_file_name != '-'
    with open(log_file_name, 'xb') if log_to_file else sys.stdout.buffer as log_file:
        binary_log = binarylog.BinaryLog(log_file)

        # Create and run the world.
        the_world = world.World(1, KERNEL.module, binary_log, local_timer_scheduling=False)
        while the_world.step() <= 400:
            pass

        the_world.log_statistics()
Exemple #2
0
    def exec_world(self, log, *world_args, **world_kwargs):
        """Create and run a world and test the produced graph against a reference."""
        graph_log = graphlog.GraphLog()

        the_world = world.World(*world_args, graph_log, **world_kwargs)
        while the_world.step() <= 400:
            pass

        svg_buf = io.BytesIO()
        graph_log.write(svg_buf)
        compare_proc = ['compare', '-', log, '-metric', 'AE', os.devnull]
        compare = subprocess.Popen(compare_proc,
                                   stdin=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   bufsize=0,
                                   cwd=os.path.dirname(sys.argv[0]))
        # graph_log.write(compare.stdin)
        _, out = compare.communicate(svg_buf.getvalue())
        compare.wait()
        self.assertEqual(compare.returncode, 0)
        self.assertEqual(out, b'0')
Exemple #3
0
    def exec_world(self, log, *world_args, **world_kwargs):
        """Create and run a world and test the produced log against a reference."""
        text_buf = io.StringIO()
        text_log = textlog.TextLog(text_buf,
                                   self.textlog_align,
                                   time_precision=16)

        the_world = world.World(*world_args, text_log, **world_kwargs)
        while the_world.step() <= 400:
            pass

        the_world.log_statistics()

        expected = open('tests/' + log, 'r')
        text_buf.seek(0)
        diff = difflib.unified_diff(text_buf.readlines(), expected.readlines(),
                                    'result', 'expected')
        has_diff = False
        for line in common.color_diff(diff):
            has_diff = True
            print(line, end='')
        expected.close()
        self.assertFalse(has_diff)