|
6 | 6 |
|
7 | 7 | import pytest |
8 | 8 |
|
9 | | -from trepan.lib import file as Mfile |
| 9 | +from trepan.lib.file import executable, lookupmodule, readable |
10 | 10 |
|
11 | 11 |
|
12 | 12 | def test_lookupmodule(): |
13 | | - m, f = Mfile.lookupmodule("os.path") |
| 13 | + m, f = lookupmodule("os.path") |
14 | 14 | assert f |
15 | 15 | assert m |
16 | | - m, f = Mfile.lookupmodule(__file__) |
| 16 | + m, f = lookupmodule(__file__) |
17 | 17 | assert f |
18 | 18 | assert m is None |
19 | | - assert (None, None) == Mfile.lookupmodule("fafdsafdsa") |
| 19 | + assert (None, None) == lookupmodule("fafdsafdsa") |
20 | 20 | return |
21 | 21 |
|
22 | 22 |
|
23 | | -pytest.mark.skipif(sys.platform == "win32", reason="Does not work on MS Windows") |
| 23 | +@pytest.mark.skipif(sys.platform == "win32", reason="Does not work on MS Windows") |
| 24 | +def test_readable(): |
| 25 | + assert not readable("fdafdsa") |
| 26 | + i = 1 |
| 27 | + for mode, can_read in [ |
| 28 | + (stat.S_IRUSR, True), # 1 |
| 29 | + (stat.S_IWUSR, False), # 2 |
| 30 | + (stat.S_IRGRP, True), # 3 |
| 31 | + (stat.S_IWGRP, False), # 4 |
| 32 | + (stat.S_IROTH, True), # 5 |
| 33 | + (stat.S_IWOTH, False), # 6 |
| 34 | + ]: |
| 35 | + f = tempfile.NamedTemporaryFile() |
| 36 | + os.chmod(f.name, mode) |
| 37 | + assert can_read == readable(f.name), f"Test {i} file mode {oct(mode)}" |
| 38 | + f.close() |
| 39 | + i += 1 |
| 40 | + pass |
| 41 | + return |
24 | 42 |
|
25 | 43 |
|
26 | | -def test_readable(): |
27 | | - assert not Mfile.readable("fdafdsa") |
28 | | - for mode, can_read in [(stat.S_IRUSR, True), (stat.S_IWUSR, False)]: |
| 44 | +@pytest.mark.skipif(sys.platform == "win32", reason="Does not work on MS Windows") |
| 45 | +def test_executable(): |
| 46 | + i = 1 |
| 47 | + for mode, can_read in [ |
| 48 | + (stat.S_IRUSR | stat.S_IXUSR, True), # 1 |
| 49 | + (stat.S_IRUSR, False), # 2 |
| 50 | + (stat.S_IWGRP | stat.S_IXGRP, False), # 3 |
| 51 | + (stat.S_IWGRP, False), # 4 |
| 52 | + (stat.S_IRGRP | stat.S_IXGRP, True), # 5 |
| 53 | + (stat.S_IRGRP, False), # 6 |
| 54 | + (stat.S_IWGRP, False), # 7 |
| 55 | + (stat.S_IROTH | stat.S_IXOTH, True), # 8 |
| 56 | + ]: |
29 | 57 | f = tempfile.NamedTemporaryFile() |
30 | 58 | os.chmod(f.name, mode) |
31 | | - assert can_read == Mfile.readable(f.name) |
| 59 | + |
| 60 | + assert can_read == executable(f.name), f"Test {i} file mode {oct(mode)}" |
32 | 61 | f.close() |
| 62 | + i += 1 |
33 | 63 | pass |
34 | 64 | return |
0 commit comments