diff options
Diffstat (limited to 'test/pathod/language')
-rw-r--r-- | test/pathod/language/test_base.py | 35 | ||||
-rw-r--r-- | test/pathod/language/test_generators.py | 34 |
2 files changed, 29 insertions, 40 deletions
diff --git a/test/pathod/language/test_base.py b/test/pathod/language/test_base.py index 85e9e53b..ec460b07 100644 --- a/test/pathod/language/test_base.py +++ b/test/pathod/language/test_base.py @@ -1,11 +1,8 @@ -import os import pytest from pathod import language from pathod.language import base, exceptions -from mitmproxy.test import tutils - def parse_request(s): return language.parse_pathoc(s).next() @@ -137,24 +134,22 @@ class TestTokValueFile: v = base.TokValue.parseString("<path")[0] assert v.path == "path" - def test_access_control(self): + def test_access_control(self, tmpdir): v = base.TokValue.parseString("<path")[0] - with tutils.tmpdir() as t: - p = os.path.join(t, "path") - with open(p, "wb") as f: - f.write(b"x" * 10000) - - assert v.get_generator(language.Settings(staticdir=t)) - - v = base.TokValue.parseString("<path2")[0] - with pytest.raises(exceptions.FileAccessDenied): - v.get_generator(language.Settings(staticdir=t)) - with pytest.raises(Exception, match="access disabled"): - v.get_generator(language.Settings()) - - v = base.TokValue.parseString("</outside")[0] - with pytest.raises(Exception, match="outside"): - v.get_generator(language.Settings(staticdir=t)) + f = tmpdir.join("path") + f.write(b"x" * 10000) + + assert v.get_generator(language.Settings(staticdir=str(tmpdir))) + + v = base.TokValue.parseString("<path2")[0] + with pytest.raises(exceptions.FileAccessDenied): + v.get_generator(language.Settings(staticdir=str(tmpdir))) + with pytest.raises(Exception, match="access disabled"): + v.get_generator(language.Settings()) + + v = base.TokValue.parseString("</outside")[0] + with pytest.raises(Exception, match="outside"): + v.get_generator(language.Settings(staticdir=str(tmpdir))) def test_spec(self): v = base.TokValue.parseString("<'one two'")[0] diff --git a/test/pathod/language/test_generators.py b/test/pathod/language/test_generators.py index b3ce0335..dc15aaa1 100644 --- a/test/pathod/language/test_generators.py +++ b/test/pathod/language/test_generators.py @@ -1,7 +1,4 @@ -import os - from pathod.language import generators -from mitmproxy.test import tutils def test_randomgenerator(): @@ -15,23 +12,20 @@ def test_randomgenerator(): assert len(g[1000:1001]) == 0 -def test_filegenerator(): - with tutils.tmpdir() as t: - path = os.path.join(t, "foo") - f = open(path, "wb") - f.write(b"x" * 10000) - f.close() - g = generators.FileGenerator(path) - assert len(g) == 10000 - assert g[0] == b"x" - assert g[-1] == b"x" - assert g[0:5] == b"xxxxx" - assert len(g[1:10]) == 9 - assert len(g[10000:10001]) == 0 - assert repr(g) - # remove all references to FileGenerator instance to close the file - # handle. - del g +def test_filegenerator(tmpdir): + f = tmpdir.join("foo") + f.write(b"x" * 10000) + g = generators.FileGenerator(str(f)) + assert len(g) == 10000 + assert g[0] == b"x" + assert g[-1] == b"x" + assert g[0:5] == b"xxxxx" + assert len(g[1:10]) == 9 + assert len(g[10000:10001]) == 0 + assert repr(g) + # remove all references to FileGenerator instance to close the file + # handle. + del g def test_transform_generator(): |