import json from parsers.infomap_log import InfomapLog if __name__ == "__main__": import argparse parser = argparse.ArgumentParser(description="Creates JSON file from Infomap Logs") parser.add_argument('outfile') parser.add_argument('infiles', nargs='+') args = parser.parse_args() logs = [] for filename in args.infiles: with open(filename) as f: parser = InfomapLog(f) logs.append(parser.parse()) with open(args.outfile, 'w') as f: json.dump(logs, f)
def setUp(self): self._stream = open(L1, "r") self._parser = InfomapLog(self._stream) self._parser.parse()
class TestInfomapLog(unittest.TestCase): def setUp(self): self._stream = open(L1, "r") self._parser = InfomapLog(self._stream) self._parser.parse() def tearDown(self): self._stream.close() def test_filename(self): self.assertEqual(PARSED['filename'], self._parser.filename()) def test_runtime(self): self.assertEqual(PARSED['runtime'], self._parser.runtime()) def test_dangling(self): self.assertEqual(PARSED['dangling_nodes'], self._parser.dangling_nodes()) def test_nodes(self): self.assertEqual(PARSED['nodes'], self._parser.nodes()) def test_links(self): self.assertEqual(PARSED['links'], self._parser.links()) def test_self_links(self): self.assertEqual(PARSED['self_links'], self._parser.self_links()) def test_num_levels(self): self.assertEqual(PARSED['num_levels'], self._parser.num_levels()) def test_num_modules(self): self.assertEqual(PARSED['num_modules'], self._parser.num_modules()) def test_num_leaves(self): self.assertEqual(PARSED['num_leaves'], self._parser.num_leaves()) def test_avg_child(self): self.assertEqual(PARSED['average_child_degree'], self._parser.average_child()) def test_module_codelength(self): self.assertEqual(PARSED['module_codelength'], self._parser.module_codelength()) def test_leaf_node_codelength(self): self.assertEqual(PARSED['leaf_node_codelength'], self._parser.leaf_node_codelength()) def test_total_codelength(self): self.assertEqual(PARSED['total_codelength'], self._parser.total_codelength()) def test_per_level_modules(self): self.assertListEqual(PARSED['per_level_num_modules'], self._parser.per_level_modules()) def test_per_level_leaf_nodes(self): self.assertListEqual(PARSED['per_level_num_leaf_nodes'], self._parser.per_level_leaf_nodes()) def test_per_level_avg_child_degree(self): self.assertListEqual(PARSED['per_level_avg_child_degree'], self._parser.per_level_avg_child_degree()) def test_per_level_module_codelength(self): self.assertListEqual(PARSED['per_level_module_codelength'], self._parser.per_level_codelength_modules()) def test_per_level_leaf_codelength(self): self.assertListEqual(PARSED['per_level_leaf_codelength'], self._parser.per_level_codelength_leaf_nodes()) def test_per_level_total_codelength(self): self.assertListEqual(PARSED['per_level_total_codelength'], self._parser.per_level_codelength_total()) def test_parse(self): self.assertDictContainsSubset(PARSED, self._parser.parse())
import json from parsers.infomap_log import InfomapLog if __name__ == "__main__": import argparse parser = argparse.ArgumentParser( description="Creates JSON file from Infomap Logs") parser.add_argument('outfile') parser.add_argument('infiles', nargs='+') args = parser.parse_args() logs = [] for filename in args.infiles: with open(filename) as f: parser = InfomapLog(f) logs.append(parser.parse()) with open(args.outfile, 'w') as f: json.dump(logs, f)