test source existence; actually fix tests
authorRuben ten Hove <redacted>
Wed, 6 Jul 2022 17:07:02 +0000 (13:07 -0400)
committerRuben ten Hove <redacted>
Wed, 6 Jul 2022 17:07:02 +0000 (13:07 -0400)
testUpdateHostsFile.py
updateHostsFile.py

index f1cf8b7b54aeeb9efc3a4eca104ec6e86459f7bc..182122be8234b3c1e4d8844581bfb2b442ef5d19 100644 (file)
@@ -1264,17 +1264,17 @@ class TestUpdateReadmeData(BaseMockDir):
 
 class TestMoveHostsFile(BaseStdout):
     @mock.patch("os.path.abspath", side_effect=lambda f: f)
-    def test_move_hosts_no_name(self, _):
+    def test_move_hosts_no_name(self, _):  # TODO: Create test which tries to move actual file
         with self.mock_property("platform.system") as obj:
             obj.return_value = "foo"
 
             mock_file = mock.Mock(name="foo")
             move_hosts_file_into_place(mock_file)
 
-            expected = ""
+            expected = "does not exist"
             output = sys.stdout.getvalue()
 
-            self.assertEqual(output, expected)
+            self.assertIn(expected, output)
 
     @mock.patch("os.path.abspath", side_effect=lambda f: f)
     def test_move_hosts_windows(self, _):
@@ -1290,17 +1290,14 @@ class TestMoveHostsFile(BaseStdout):
 
     @mock.patch("os.path.abspath", side_effect=lambda f: f)
     @mock.patch("subprocess.call", return_value=0)
-    def test_move_hosts_posix(self, *_):
+    def test_move_hosts_posix(self, *_):  # TODO: create test which tries to move an actual file
         with self.mock_property("platform.system") as obj:
             obj.return_value = "Linux"
 
             mock_file = mock.Mock(name="foo")
             move_hosts_file_into_place(mock_file)
 
-            expected = (
-                "Moving the file requires administrative "
-                "privileges. You might need to enter your password."
-            )
+            expected = "does not exist."
             output = sys.stdout.getvalue()
             self.assertIn(expected, output)
 
@@ -1313,7 +1310,7 @@ class TestMoveHostsFile(BaseStdout):
             mock_file = mock.Mock(name="foo")
             move_hosts_file_into_place(mock_file)
 
-            expected = "Moving the file failed."
+            expected = "does not exist."
             output = sys.stdout.getvalue()
             self.assertIn(expected, output)
 
index ba9b9b45d47a0b63b95c3eb1700d8735398e15dd..45a008a050551f471c7604ba8094278ede9ea6e5 100755 (executable)
@@ -1281,6 +1281,14 @@ def move_hosts_file_into_place(final_file):
     """  # noqa: W605
 
     filename = os.path.abspath(final_file.name)
+
+    try:
+        if not Path(filename).exists():
+            raise FileNotFoundError
+    except Exception:
+        print_failure(f"{filename} does not exist.")
+        return False
+
     if platform.system() == "Windows":
         target_file = str(Path(os.getenv("SystemRoot")) / "system32" / "drivers" / "etc" / "hosts")
     else:
git clone https://git.99rst.org/PROJECT