summaryrefslogtreecommitdiffstats
path: root/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestNonexistent.py
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-08-21 17:06:35 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-08-21 17:06:35 -0400
commit556ac5660c22eb8316bff03cc3ccec5c82005b7c (patch)
treecd1829f50f535e4580b1a2ca6de89e45d5280526 /testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestNonexistent.py
parent52b01a5a0a308f05affad9b72e2c1406cb807021 (diff)
downloadbcfg2-556ac5660c22eb8316bff03cc3ccec5c82005b7c.tar.gz
bcfg2-556ac5660c22eb8316bff03cc3ccec5c82005b7c.tar.bz2
bcfg2-556ac5660c22eb8316bff03cc3ccec5c82005b7c.zip
removed context managers from unit tests
Diffstat (limited to 'testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestNonexistent.py')
-rw-r--r--testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestNonexistent.py95
1 files changed, 46 insertions, 49 deletions
diff --git a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestNonexistent.py b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestNonexistent.py
index 2b46bd9e6..fbd9a11ad 100644
--- a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestNonexistent.py
+++ b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestNonexistent.py
@@ -1,6 +1,5 @@
import os
import copy
-import unittest
import lxml.etree
from mock import Mock, MagicMock, patch
from Bcfg2.Client.Tools.POSIX.Nonexistent import *
@@ -14,68 +13,66 @@ class TestPOSIXNonexistent(TestPOSIXTool):
@patch("os.path.lexists")
def test_verify(self, mock_lexists):
entry = lxml.etree.Element("Path", name="/test", type="nonexistent")
- ptool = self.get_obj()
for val in [True, False]:
mock_lexists.reset_mock()
mock_lexists.return_value = val
- self.assertEqual(ptool.verify(entry, []), not val)
+ self.assertEqual(self.ptool.verify(entry, []), not val)
mock_lexists.assert_called_with(entry.get("name"))
@patch("os.rmdir")
@patch("os.remove")
+ @patch("os.path.isdir")
@patch("shutil.rmtree")
- def test_install(self, mock_rmtree, mock_remove, mock_rmdir):
+ def test_install(self, mock_rmtree, mock_isdir, mock_remove, mock_rmdir):
entry = lxml.etree.Element("Path", name="/test", type="nonexistent")
- ptool = self.get_obj()
- with patch("os.path.isdir") as mock_isdir:
- def reset():
- mock_isdir.reset_mock()
- mock_remove.reset_mock()
- mock_rmdir.reset_mock()
- mock_rmtree.reset_mock()
+ def reset():
+ mock_isdir.reset_mock()
+ mock_remove.reset_mock()
+ mock_rmdir.reset_mock()
+ mock_rmtree.reset_mock()
- mock_isdir.return_value = False
- self.assertTrue(ptool.install(entry))
- mock_remove.assert_called_with(entry.get("name"))
+ mock_isdir.return_value = False
+ self.assertTrue(self.ptool.install(entry))
+ mock_remove.assert_called_with(entry.get("name"))
- reset()
- mock_remove.side_effect = OSError
- self.assertFalse(ptool.install(entry))
- mock_remove.assert_called_with(entry.get("name"))
+ reset()
+ mock_remove.side_effect = OSError
+ self.assertFalse(self.ptool.install(entry))
+ mock_remove.assert_called_with(entry.get("name"))
- reset()
- mock_isdir.return_value = True
- self.assertTrue(ptool.install(entry))
- mock_rmdir.assert_called_with(entry.get("name"))
+ reset()
+ mock_isdir.return_value = True
+ self.assertTrue(self.ptool.install(entry))
+ mock_rmdir.assert_called_with(entry.get("name"))
- reset()
- mock_rmdir.side_effect = OSError
- self.assertFalse(ptool.install(entry))
- mock_rmdir.assert_called_with(entry.get("name"))
-
- reset()
- entry.set("recursive", "true")
- self.assertTrue(ptool.install(entry))
- mock_rmtree.assert_called_with(entry.get("name"))
+ reset()
+ mock_rmdir.side_effect = OSError
+ self.assertFalse(self.ptool.install(entry))
+ mock_rmdir.assert_called_with(entry.get("name"))
- reset()
- mock_rmtree.side_effect = OSError
- self.assertFalse(ptool.install(entry))
- mock_rmtree.assert_called_with(entry.get("name"))
-
- reset()
- child_entry = lxml.etree.Element("Path", name="/test/foo",
- type="nonexistent")
- ptool = self.get_obj(posix=get_posix_object(config=get_config([child_entry])))
- mock_rmtree.side_effect = None
- self.assertTrue(ptool.install(entry))
- mock_rmtree.assert_called_with(entry.get("name"))
+ reset()
+ entry.set("recursive", "true")
+ self.assertTrue(self.ptool.install(entry))
+ mock_rmtree.assert_called_with(entry.get("name"))
- reset()
- child_entry = lxml.etree.Element("Path", name="/test/foo",
- type="file")
- ptool = self.get_obj(posix=get_posix_object(config=get_config([child_entry])))
- mock_rmtree.side_effect = None
- self.assertFalse(ptool.install(entry))
+ reset()
+ mock_rmtree.side_effect = OSError
+ self.assertFalse(self.ptool.install(entry))
+ mock_rmtree.assert_called_with(entry.get("name"))
+
+ reset()
+ child_entry = lxml.etree.Element("Path", name="/test/foo",
+ type="nonexistent")
+ ptool = self.get_obj(posix=get_posix_object(config=get_config([child_entry])))
+ mock_rmtree.side_effect = None
+ self.assertTrue(ptool.install(entry))
+ mock_rmtree.assert_called_with(entry.get("name"))
+
+ reset()
+ child_entry = lxml.etree.Element("Path", name="/test/foo",
+ type="file")
+ ptool = self.get_obj(posix=get_posix_object(config=get_config([child_entry])))
+ mock_rmtree.side_effect = None
+ self.assertFalse(ptool.install(entry))