diff --git a/_py/path/common.py b/_py/path/common.py index d138bc6aa..9352a4a11 100644 --- a/_py/path/common.py +++ b/_py/path/common.py @@ -300,6 +300,10 @@ newline will be removed from the end of each line. """ else: res.sort() + def samefile(self, other): + """ return True if other refers to the same stat object as self. """ + return self.strpath == str(other) + class FNMatcher: def __init__(self, pattern): self.pattern = pattern diff --git a/_py/path/local.py b/_py/path/local.py index 1e87120c0..d0c4ce43d 100644 --- a/_py/path/local.py +++ b/_py/path/local.py @@ -70,7 +70,7 @@ class PosixPath(common.PathBase): def samefile(self, other): """ return True if other refers to the same stat object as self. """ - return py.std.os.path.samefile(str(self), str(other)) + return py.error.checked_call(os.path.samefile, str(self), str(other)) def getuserid(user): import pwd diff --git a/conftest.py b/conftest.py index 003a70e2d..58944ad56 100644 --- a/conftest.py +++ b/conftest.py @@ -1,6 +1,15 @@ +import py + pytest_plugins = '_pytest doctest pytester'.split() -rsyncdirs = ['conftest.py', 'py', 'doc', 'testing'] + +rsyncdirs = ['conftest.py', 'bin', 'py', 'doc', 'testing'] +try: + import execnet +except ImportError: + pass +else: + rsyncdirs.append(str(py.path.local(execnet.__file__).dirpath())) import py def pytest_addoption(parser): diff --git a/testing/io_/test_terminalwriter.py b/testing/io_/test_terminalwriter.py index 91d1cedaf..bc4c172eb 100644 --- a/testing/io_/test_terminalwriter.py +++ b/testing/io_/test_terminalwriter.py @@ -42,7 +42,7 @@ def test_unicode_encoding(): l = [] tw = py.io.TerminalWriter(l.append, encoding=encoding) tw.line(msg) - assert l[0] == msg.encode(encoding) + assert l[0].strip() == msg.encode(encoding) class BaseTests: def test_line(self): diff --git a/testing/log/test_log.py b/testing/log/test_log.py index 36c524cca..20168d25f 100644 --- a/testing/log/test_log.py +++ b/testing/log/test_log.py @@ -118,7 +118,7 @@ class TestLogConsumer: def test_log_file(self): customlog = tempdir.join('log.out') - py.log.setconsumer("default", open(str(customlog), 'w', buffering=1)) + py.log.setconsumer("default", open(str(customlog), 'w', buffering=0)) py.log.Producer("default")("hello world #1") assert customlog.readlines() == ['[default] hello world #1\n'] diff --git a/testing/path/test_local.py b/testing/path/test_local.py index 333025fba..82de8a318 100644 --- a/testing/path/test_local.py +++ b/testing/path/test_local.py @@ -368,14 +368,19 @@ def test_homedir(): homedir = py.path.local._gethomedir() assert homedir.check(dir=1) +def test_samefile(tmpdir): + assert tmpdir.samefile(tmpdir) + p = tmpdir.ensure("hello") + assert p.samefile(p) + class TestWINLocalPath: pytestmark = py.test.mark.skipif("sys.platform != 'win32'") - def test_owner_group_not_implemented(self): + def test_owner_group_not_implemented(self, path1): py.test.raises(NotImplementedError, "path1.stat().owner") py.test.raises(NotImplementedError, "path1.stat().group") - def test_chmod_simple_int(self): + def test_chmod_simple_int(self, path1): py.builtin.print_("path1 is", path1) mode = path1.stat().mode # Ensure that we actually change the mode to something different. @@ -388,18 +393,18 @@ class TestWINLocalPath: path1.chmod(mode) assert path1.stat().mode == mode - def test_path_comparison_lowercase_mixed(self): + def test_path_comparison_lowercase_mixed(self, path1): t1 = path1.join("a_path") t2 = path1.join("A_path") assert t1 == t1 assert t1 == t2 - def test_relto_with_mixed_case(self): + def test_relto_with_mixed_case(self, path1): t1 = path1.join("a_path", "fiLe") t2 = path1.join("A_path") assert t1.relto(t2) == "fiLe" - def test_allow_unix_style_paths(self): + def test_allow_unix_style_paths(self, path1): t1 = path1.join('a_path') assert t1 == str(path1) + '\\a_path' t1 = path1.join('a_path/') @@ -407,7 +412,7 @@ class TestWINLocalPath: t1 = path1.join('dir/a_path') assert t1 == str(path1) + '\\dir\\a_path' - def test_sysfind_in_currentdir(self): + def test_sysfind_in_currentdir(self, path1): cmd = py.path.local.sysfind('cmd') root = cmd.new(dirname='', basename='') # c:\ in most installations old = root.chdir() @@ -420,11 +425,6 @@ class TestWINLocalPath: class TestPOSIXLocalPath: pytestmark = py.test.mark.skipif("sys.platform == 'win32'") - def test_samefile(self, tmpdir): - assert tmpdir.samefile(tmpdir) - p = tmpdir.ensure("hello") - assert p.samefile(p) - def test_hardlink(self, tmpdir): linkpath = tmpdir.join('test') filepath = tmpdir.join('file') diff --git a/testing/test_py_imports.py b/testing/test_py_imports.py index dd591e65e..be87c01d9 100644 --- a/testing/test_py_imports.py +++ b/testing/test_py_imports.py @@ -8,7 +8,8 @@ def checksubpackage(name): keys = dir(obj) assert len(keys) > 0 print (obj.__map__) - assert getattr(obj, '__map__') == {} + for name in obj.__map__: + assert hasattr(obj, name), (obj, name) def test_dir(): for name in dir(py):