Skip to content

Commit

Permalink
Merge 565e7b3 into 0d78a7a
Browse files Browse the repository at this point in the history
  • Loading branch information
mristin committed Oct 10, 2019
2 parents 0d78a7a + 565e7b3 commit d29e51a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
4 changes: 2 additions & 2 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import os
import pathlib
import pwd
import getpass
from typing import Optional # pylint: disable=unused-import

import spur.ssh
Expand Down Expand Up @@ -34,7 +34,7 @@ def params_from_environ() -> Params:
params.username = os.environ['TEST_SSH_USERNAME']
else:
# Get the current local username
params.username = pwd.getpwuid(os.getuid())[0]
params.username = getpass.getuser()

if 'TEST_SSH_PASSWORD' in os.environ:
params.password = str(os.environ['TEST_SSH_PASSWORD'])
Expand Down
32 changes: 17 additions & 15 deletions tests/test_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import hashlib
import io
import pathlib
import platform
import time
import unittest
import uuid
Expand All @@ -26,9 +27,7 @@ def test_fail_connect_with_retries(self):
except ConnectionError as err:
connerr = err

self.assertEqual(
"Failed to connect after 2 retries to some-nonexisting-hostname.com: Error creating SSH connection\n"
"Original error: [Errno -2] Name or service not known", str(connerr))
self.assertIsNotNone(connerr)


class TestProperties(unittest.TestCase):
Expand Down Expand Up @@ -241,7 +240,7 @@ def test_read_bytes_not_found(self):
except FileNotFoundError as err:
notfounderr = err

self.assertEqual("The remote path was not found: {}".format(pth), str(notfounderr))
self.assertEqual("The remote path was not found: {}".format(pth.as_posix()), str(notfounderr))

def test_write_read_text(self):
for consistent in [True, False]:
Expand Down Expand Up @@ -381,7 +380,7 @@ def test_is_dir(self):
os_err = err

self.assertIsNotNone(os_err)
self.assertEqual("Remote file does not exist: {}".format(pth_to_nonexisting), str(os_err))
self.assertEqual("Remote file does not exist: {}".format(pth_to_nonexisting.as_posix()), str(os_err))

def test_is_symlink(self):
with spurplus.TemporaryDirectory(shell=self.shell) as tmpdir:
Expand Down Expand Up @@ -412,7 +411,7 @@ def test_is_symlink(self):
except FileNotFoundError as err:
notfounderr = err

self.assertEqual("Remote file does not exist: {}".format(pth_to_nonexisting), str(notfounderr))
self.assertEqual("Remote file does not exist: {}".format(pth_to_nonexisting.as_posix()), str(notfounderr))

def test_symlink(self):
with spurplus.TemporaryDirectory(shell=self.shell) as tmpdir:
Expand Down Expand Up @@ -446,8 +445,8 @@ def test_symlink(self):
file_exists_err = err

self.assertIsNotNone(file_exists_err)
self.assertEqual("The destination of the symbolic link already exists: {}".format(pth_to_file_link),
str(file_exists_err))
self.assertEqual("The destination of the symbolic link already exists: {}".format(
pth_to_file_link.as_posix()), str(file_exists_err))

def test_symlink_with_nonexisting(self):
with spurplus.TemporaryDirectory(shell=self.shell) as tmpdir:
Expand All @@ -472,7 +471,7 @@ def test_symlink_with_nonexisting(self):

self.assertIsNotNone(os_err)
self.assertEqual("Failed to create the symbolic link to {} at {}".format(
pth_to_file, pth_link_in_nonexisting_dir), str(os_err))
pth_to_file.as_posix(), pth_link_in_nonexisting_dir.as_posix()), str(os_err))


class TestRemove(unittest.TestCase):
Expand All @@ -494,8 +493,8 @@ def test_file(self):
except FileNotFoundError as err:
notfounderr = err

self.assertEqual("Remote file does not exist and thus can not be removed: {}".format(pth_to_file),
str(notfounderr))
self.assertEqual("Remote file does not exist and thus can not be removed: {}".format(
pth_to_file.as_posix()), str(notfounderr))

self.shell.write_text(remote_path=pth_to_file, text="hello")

Expand Down Expand Up @@ -551,9 +550,8 @@ def test_non_empty_dir(self):
os_err = err

self.assertIsNotNone(os_err)
self.assertEqual(
"The remote directory is not empty and the recursive flag was not set: {}".format(pth_to_some_dir),
str(os_err))
self.assertEqual("The remote directory is not empty and the recursive flag was not set: {}".format(
pth_to_some_dir.as_posix()), str(os_err))

def test_recursive(self):
with spurplus.TemporaryDirectory(shell=self.shell) as tmpdir:
Expand Down Expand Up @@ -619,7 +617,7 @@ def test_local_permissions_missing_file(self): # pylint: disable=invalid-name

self.assertIsNotNone(not_found_err)
self.assertEqual("Remote file to be chmod'ed does not exist: {}".format(
remote_tmpdir.path / "some-dir/some-file"), str(not_found_err))
(remote_tmpdir.path / "some-dir/some-file").as_posix()), str(not_found_err))

def test_local_dir_permission_invalid_pth(self): # pylint: disable=invalid-name
with spurplus.TemporaryDirectory(shell=self.shell) as remote_tmpdir, \
Expand Down Expand Up @@ -883,6 +881,8 @@ def test_local_only_file(self):
self.assertTrue(self.shell.exists(remote_path=remote_pth_to_file))
self.assertEqual("hello", self.shell.read_text(remote_path=remote_pth_to_file))

@unittest.skipIf(platform.system() == "Windows", "Symbolic links admin privileges on Windows; "
"requesting admin privileges for unit testing is inappropriate.")
def test_local_only_link(self):
with spurplus.TemporaryDirectory(shell=self.shell) as remote_tmpdir, \
temppathlib.TemporaryDirectory() as local_tmpdir:
Expand Down Expand Up @@ -981,6 +981,8 @@ def test_remote_subdir_is_deleted(self):
self.assertFalse(self.shell.exists(remote_path=remote_pth_to_dir))
self.assertFalse(self.shell.exists(remote_path=remote_pth_to_subdir))

@unittest.skipIf(platform.system() == "Windows", "os.chmod is not properly implemented in Windows; "
"see https://stackoverflow.com/q/27500067")
def test_preserve_permissions(self):
with spurplus.TemporaryDirectory(shell=self.shell) as remote_tmpdir, \
temppathlib.TemporaryDirectory() as local_tmpdir:
Expand Down

0 comments on commit d29e51a

Please sign in to comment.