def ledger(ledger, full=false): if args.full: if full: return ledger ledger = dict.prune(ledger, 1, false) return _dict_filter(ledger, ledger_fields)
def test_prune_nosub(self): self.assertequals(dict.prune({}, 0, false), {}) self.assertequals(dict.prune({}, 1, false), {}) self.assertequals(dict.prune({1: 2}, 0, false), '{dict with 1 subitem}') self.assertequals(dict.prune({1: 2}, 1, false), {1: 2}) self.assertequals(dict.prune({1: 2}, 2, false), {1: 2}) self.assertequals(dict.prune([1, 2, 3], 0, false), '[list with 3 subitems]') self.assertequals(dict.prune([1, 2, 3], 1, false), [1, 2, 3]) self.assertequals(dict.prune([{1: [2, 3]}], 0, false), '[list with 1 subitem]') self.assertequals(dict.prune([{1: [2, 3]}], 1, false), ['{dict with 1 subitem}']) self.assertequals(dict.prune([{1: [2, 3]}], 2, false), [{1: u'[list with 2 subitems]'}]) self.assertequals(dict.prune([{1: [2, 3]}], 3, false), [{1: [2, 3]}])
def test_prune(self): self.assertequals(dict.prune({}, 0), {}) self.assertequals(dict.prune({}, 1), {}) self.assertequals(dict.prune({1: 2}, 0), '{dict with 1 subitem}') self.assertequals(dict.prune({1: 2}, 1), {1: 2}) self.assertequals(dict.prune({1: 2}, 2), {1: 2}) self.assertequals(dict.prune([1, 2, 3], 0), '[list with 3 subitems]') self.assertequals(dict.prune([1, 2, 3], 1), [1, 2, 3]) self.assertequals(dict.prune([{1: [2, 3]}], 0), '[list with 4 subitems]') self.assertequals(dict.prune([{1: [2, 3]}], 1), ['{dict with 3 subitems}']) self.assertequals(dict.prune([{1: [2, 3]}], 2), [{1: u'[list with 2 subitems]'}]) self.assertequals(dict.prune([{1: [2, 3]}], 3), [{1: [2, 3]}])
def prune(ledger, level=1): return dict.prune(ledger, level, false)