def test_revision_generator_notices(self, init, merge_changes): init.return_value = None b = Builder() # Don't need parameters as init's been mocked out aaaa = {'document_number': 'aaaa', 'effective_on': '2012-12-12', 'publication_date': '2011-11-11', 'changes': []} bbbb = {'document_number': 'bbbb', 'effective_on': '2012-12-12', 'publication_date': '2011-11-12', 'changes': []} cccc = {'document_number': 'cccc', 'effective_on': '2013-01-01', 'publication_date': '2012-01-01', 'changes': []} b.notices = [aaaa, bbbb, cccc] b.eff_notices = {'2012-12-12': [aaaa, bbbb], '2013-01-01': [cccc]} b.doc_number = 'aaaa' b.checkpointer = NullCheckpointer() tree = Node(label=['1111']) version_list = [] notice_lists = [] for notice, _, _, notices in b.revision_generator(tree): version_list.append(notice['document_number']) notice_lists.append(notices) self.assertEqual(['bbbb', 'cccc'], version_list) self.assertEqual(2, len(notice_lists)) self.assertEqual(2, len(notice_lists[0])) self.assertTrue(aaaa in notice_lists[0]) self.assertTrue(bbbb in notice_lists[0]) self.assertEqual(3, len(notice_lists[1])) self.assertTrue(aaaa in notice_lists[1]) self.assertTrue(bbbb in notice_lists[1]) self.assertTrue(cccc in notice_lists[1])
def test_revision_generator_notices(self, init, merge_changes): init.return_value = None b = Builder() # Don't need parameters as init's been mocked out aaaa = {'document_number': 'aaaa', 'effective_on': '2012-12-12', 'publication_date': '2011-11-11', 'changes': []} bbbb = {'document_number': 'bbbb', 'effective_on': '2012-12-12', 'publication_date': '2011-11-12', 'changes': []} cccc = {'document_number': 'cccc', 'effective_on': '2013-01-01', 'publication_date': '2012-01-01', 'changes': []} b.notices = [aaaa, bbbb, cccc] b.eff_notices = {'2012-12-12': [aaaa, bbbb], '2013-01-01': [cccc]} b.doc_number = 'aaaa' tree = Node(label=['1111']) version_list = [] notice_lists = [] for notice, _, _, notices in b.revision_generator(tree): version_list.append(notice['document_number']) notice_lists.append(notices) self.assertEqual(['bbbb', 'cccc'], version_list) self.assertEqual(2, len(notice_lists)) self.assertEqual(2, len(notice_lists[0])) self.assertTrue(aaaa in notice_lists[0]) self.assertTrue(bbbb in notice_lists[0]) self.assertEqual(3, len(notice_lists[1])) self.assertTrue(aaaa in notice_lists[1]) self.assertTrue(bbbb in notice_lists[1]) self.assertTrue(cccc in notice_lists[1])
def test_changes_in_sequence_skips(self, init, merge_changes): """Skips over notices which occurred _before_ our starting point""" init.return_value = None b = Builder() # Don't need parameters as init's been mocked out aaaa = {'document_number': 'aaaa', 'effective_on': '2012-12-12', 'publication_date': '2011-11-11', 'changes': []} bbbb = {'document_number': 'bbbb', 'effective_on': '2012-12-12', 'publication_date': '2011-11-12', 'changes': []} cccc = {'document_number': 'cccc', 'effective_on': '2013-01-01', 'publication_date': '2012-01-01', 'changes': []} b.eff_notices = {'2012-12-12': [aaaa, bbbb], '2013-01-01': [cccc]} b.doc_number = bbbb['document_number'] changes = list(b.changes_in_sequence()) self.assertEqual(len(changes), 1) self.assertEqual(cccc['document_number'], changes[0][0]) self.assertEqual(cccc['document_number'], merge_changes.call_args[0][0])
builder.write_notices() # Always do at least the first reg logger.info("Version %s", doc_number) builder.write_regulation(reg_tree) layer_cache = LayerCacheAggregator() builder.gen_and_write_layers(reg_tree, sys.argv[4:6], layer_cache) layer_cache.replace_using(reg_tree) if len(sys.argv) < 7 or sys.argv[6].lower() == 'true': all_versions = {doc_number: reg_tree} for last_notice, old, new_tree, notices in builder.revision_generator( reg_tree): version = last_notice['document_number'] logger.info("Version %s", version) all_versions[version] = new_tree builder.doc_number = version builder.write_regulation(new_tree) layer_cache.invalidate_by_notice(last_notice) builder.gen_and_write_layers(new_tree, sys.argv[4:6], layer_cache, notices) layer_cache.replace_using(new_tree) # now build diffs - include "empty" diffs comparing a version to itself for lhs_version, lhs_tree in all_versions.iteritems(): for rhs_version, rhs_tree in all_versions.iteritems(): comparer = treediff.Compare(lhs_tree, rhs_tree) comparer.compare() builder.writer.diff(reg_tree.label_id(), lhs_version, rhs_version).write(comparer.changes)
layer_cache = LayerCacheAggregator() builder.gen_and_write_layers(reg_tree, act_title_and_section, layer_cache) layer_cache.replace_using(reg_tree) # this used to assume implicitly that if gen-diffs was not specified it was # True; changed it to explicit check if args.generate_diffs: all_versions = {doc_number: reg_tree} for last_notice, old, new_tree, notices in builder.revision_generator( reg_tree): version = last_notice['document_number'] logger.info("Version %s", version) all_versions[version] = new_tree builder.doc_number = version builder.write_regulation(new_tree) layer_cache.invalidate_by_notice(last_notice) builder.gen_and_write_layers(new_tree, act_title_and_section, layer_cache, notices) layer_cache.replace_using(new_tree) # convert to frozen trees for doc in all_versions: all_versions[doc] = FrozenNode.from_node(all_versions[doc]) # now build diffs - include "empty" diffs comparing a version to itself for lhs_version, lhs_tree in all_versions.iteritems(): for rhs_version, rhs_tree in all_versions.iteritems(): changes = checkpointer.checkpoint( "-".join(["diff", lhs_version, rhs_version]),