def test_flatten(): tests = [(([1, 2, 3], ), [1, 2, 3]), (([1, [2, 3]], ), [1, 2, 3]), (([1, [2, [3]]], ), [1, 2, 3]), (([1, [2, [3], 4], 5, 6], ), [1, 2, 3, 4, 5, 6]), ((['foo', 'bar'], ), ['foo', 'bar']), ((['ab', 'cd'], ()), ['a', 'b', 'c', 'd'])] for args, result in tests: Assert(list(flatten(*args))) == result
def test_flatten(): tests = [ (([1, 2, 3], ), [1, 2, 3]), (([1, [2, 3]], ), [1, 2, 3]), (([1, [2, [3]]], ), [1, 2, 3]), (([1, [2, [3], 4], 5, 6], ), [1, 2, 3, 4, 5, 6]), ((['foo', 'bar'], ), ['foo', 'bar']), ((['ab', 'cd'], ()), ['a', 'b', 'c', 'd']) ] for args, result in tests: Assert(list(flatten(*args))) == result
def __init__(self, *paths): self.paths = map(str, flatten(paths)) self.path = '/'.join(self.paths) self.context = {}