Ver código fonte

Avoid stubbing options.exists where unnecessary

Mike Naberezny 10 anos atrás
pai
commit
c64a372baa
1 arquivos alterados com 17 adições e 33 exclusões
  1. 17 33
      supervisor/tests/test_options.py

+ 17 - 33
supervisor/tests/test_options.py

@@ -331,33 +331,25 @@ class ClientOptionsTests(unittest.TestCase):
         self.assertEqual(options.history_file, '/path/to/histdir/.supervisorctl.hist')
 
     def test_read_config_not_found(self):
+        nonexistent = os.path.join(os.path.dirname(__file__), 'nonexistent')
         instance = self._makeOne()
-        def dummy_exists(fn):
-            return False
-        instance.exists = dummy_exists
-
         try:
-            instance.read_config('filename')
-        except ValueError as e:
-            self.assertTrue("could not find config file" in str(e))
-        else:
-            self.fail("expected exception")
+            instance.read_config(nonexistent)
+            self.fail("nothing raised")
+        except ValueError as exc:
+            self.assertTrue("could not find config file" in exc.args[0])
 
     def test_read_config_unreadable(self):
         instance = self._makeOne()
-        def dummy_exists(fn):
-            return True
-        instance.exists = dummy_exists
         def dummy_open(fn, mode):
             raise IOError(errno.EACCES, 'Permission denied: %s' % fn)
         instance.open = dummy_open
 
         try:
-            instance.read_config('filename')
-        except ValueError as e:
-            self.assertTrue("could not read config file" in str(e))
-        else:
+            instance.read_config(__file__)
             self.fail("expected exception")
+        except ValueError as exc:
+            self.assertTrue("could not read config file" in exc.args[0])
 
     def test_read_config_no_supervisord_section_raises_valueerror(self):
         instance = self._makeOne()
@@ -735,33 +727,25 @@ class ServerOptionsTests(unittest.TestCase):
         self.assertFalse(old_warning in instance.parse_warnings)
 
     def test_read_config_not_found(self):
+        nonexistent = os.path.join(os.path.dirname(__file__), 'nonexistent')
         instance = self._makeOne()
-        def dummy_exists(fn):
-            return False
-        instance.exists = dummy_exists
-
         try:
-            instance.read_config('filename')
-        except ValueError as e:
-            self.assertTrue("could not find config file" in str(e))
-        else:
-            self.fail("expected exception")
+            instance.read_config(nonexistent)
+            self.fail("nothing raised")
+        except ValueError as exc:
+            self.assertTrue("could not find config file" in exc.args[0])
 
     def test_read_config_unreadable(self):
         instance = self._makeOne()
-        def dummy_exists(fn):
-            return True
-        instance.exists = dummy_exists
         def dummy_open(fn, mode):
             raise IOError(errno.EACCES, 'Permission denied: %s' % fn)
         instance.open = dummy_open
 
         try:
-            instance.read_config('filename')
-        except ValueError as e:
-            self.assertTrue("could not read config file" in str(e))
-        else:
-            self.fail("expected exception")
+            instance.read_config(__file__)
+            self.fail("nothing raised")
+        except ValueError as exc:
+            self.assertTrue("could not read config file" in exc.args[0])
 
     def test_read_config_malformed_config_file_raises_valueerror(self):
         instance = self._makeOne()