Sequel to #25, added more tests, discovered a bug in the process, fixed the bug, added some more tests.
In case you're curious about the bug, turns out os.path.split only splits a path into two parts. So os.path.split("long/path/to") will yield "long/path", "to". And, earlier we were iterating over the result of os.path.split expecting to get all the parts one by one, i.e. ["long", "path", "to"]. Now, we first collect all the path fragments and then loop over them.
fragments = []
cur_head = os.path.dirname(filename)
while cur_head:
cur_head, tail = os.path.split(cur_head)
fragments.insert(0, tail) # insert at the beginning
Sequel to #25, added more tests, discovered a bug in the process, fixed the bug, added some more tests.
In case you're curious about the bug, turns out
os.path.split
only splits a path into two parts. Soos.path.split("long/path/to")
will yield"long/path", "to"
. And, earlier we were iterating over the result ofos.path.split
expecting to get all the parts one by one, i.e.["long", "path", "to"]
. Now, we first collect all the path fragments and then loop over them.