| 1 | |
| 2 | from rpython.tool import udir |
| 3 | |
| 4 | def test_make_udir(): |
| 5 | root = str(udir.udir.ensure('make_udir1', dir=1)) |
| 6 | p1 = udir.make_udir(dir=root) |
| 7 | p2 = udir.make_udir(dir=root) |
| 8 | assert p1.relto(root).startswith('usession-') |
| 9 | assert p2.relto(root).startswith('usession-') |
| 10 | assert p1.basename.endswith('-0') |
| 11 | assert p2.basename.endswith('-1') |
| 12 | |
| 13 | def test_make_udir_with_basename(): |
| 14 | root = str(udir.udir.ensure('make_udir2', dir=1)) |
| 15 | p1 = udir.make_udir(dir=root, basename='foobar') |
| 16 | def assert_relto(path, root, expected): |
| 17 | assert path.relto(root) == expected, path.relto(root) |
| 18 | assert p1.relto(root) == 'usession-foobar-0' |
| 19 | p1 = udir.make_udir(dir=root, basename='-foobar') |
| 20 | assert p1.relto(root) == 'usession-foobar-1' |
| 21 | p1 = udir.make_udir(dir=root, basename='foobar-') |
| 22 | assert p1.relto(root) == 'usession-foobar-2' |
| 23 | p1 = udir.make_udir(dir=root, basename='-foobar-') |
| 24 | assert p1.relto(root) == 'usession-foobar-3' |
| 25 | p1 = udir.make_udir(dir=root, basename='') |
| 26 | assert p1.relto(root) == 'usession-0' |
| 27 | p1 = udir.make_udir(dir=root, basename='-') |
| 28 | assert p1.relto(root) == 'usession-1' |
| 29 | p1 = udir.make_udir(dir=root, basename='fun/bar') |
| 30 | assert p1.relto(root) == 'usession-fun--bar-0' |