summaryrefslogtreecommitdiffstats
path: root/testsuite
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander.sulfrian@fu-berlin.de>2015-07-22 17:15:07 +0200
committerAlexander Sulfrian <alexander.sulfrian@fu-berlin.de>2015-07-22 17:15:07 +0200
commitb54c32c861b517b889b1cd6c0bbe082b8d93e5d2 (patch)
tree0deb7db3dc8c8de428665385086620fd74c1ae02 /testsuite
parent06a6fce3f2f5c78a12937d4e52de3d824e3dd5e0 (diff)
downloadbcfg2-b54c32c861b517b889b1cd6c0bbe082b8d93e5d2.tar.gz
bcfg2-b54c32c861b517b889b1cd6c0bbe082b8d93e5d2.tar.bz2
bcfg2-b54c32c861b517b889b1cd6c0bbe082b8d93e5d2.zip
tests: is_string is now in Bcfg2.Utils
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py28
-rw-r--r--testsuite/Testsrc/Testlib/TestUtils.py15
2 files changed, 21 insertions, 22 deletions
diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py
index 69dd562be..47d3b84ed 100644
--- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py
+++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py
@@ -37,22 +37,6 @@ class TestPOSIXFile(TestPOSIXTool):
entry.text = "text"
self.assertTrue(ptool.fully_specified(entry))
- def test_is_string(self):
- ptool = self.get_obj()
-
- for char in list(range(8)) + list(range(14, 32)):
- self.assertFalse(ptool._is_string("foo" + chr(char) + "bar",
- 'UTF-8'))
- for char in list(range(9, 14)) + list(range(33, 128)):
- self.assertTrue(ptool._is_string("foo" + chr(char) + "bar",
- 'UTF-8'))
- ustr = 'é'
- self.assertTrue(ptool._is_string(ustr, 'UTF-8'))
- if not inPy3k:
- self.assertFalse(ptool._is_string("foo" + chr(128) + "bar",
- 'ascii'))
- self.assertFalse(ptool._is_string(ustr, 'ascii'))
-
def test_get_data(self):
orig_entry = lxml.etree.Element("Path", name="/test", type="file")
Bcfg2.Options.setup.encoding = "ascii"
@@ -216,7 +200,8 @@ class TestPOSIXFile(TestPOSIXTool):
mock_unlink.assert_called_with(newfile)
@patch("%s.open" % builtins)
- def test__get_diffs(self, mock_open):
+ @patch("Bcfg2.Utils")
+ def test__get_diffs(self, mock_utils, mock_open):
orig_entry = lxml.etree.Element("Path", name="/test", type="file",
mode='0644', owner='root',
group='root')
@@ -226,16 +211,15 @@ class TestPOSIXFile(TestPOSIXTool):
ptool = self.get_obj()
ptool._get_data = Mock()
ptool._diff = Mock()
- ptool._is_string = Mock()
def reset():
- ptool._is_string.reset_mock()
+ mock_utils.is_string.reset_mock()
ptool._get_data.reset_mock()
ptool._diff.reset_mock()
mock_open.reset_mock()
return copy.deepcopy(orig_entry)
- ptool._is_string.return_value = True
+ mock_utils.is_string.return_value = True
ptool._get_data.return_value = (orig_entry.text, False)
mock_open.return_value.read.return_value = ondisk
ptool._diff.return_value = ["-test2", "+test"]
@@ -250,7 +234,7 @@ class TestPOSIXFile(TestPOSIXTool):
# binary data on disk
entry = reset()
- ptool._is_string.return_value = False
+ mock_utils.is_string.return_value = False
ptool._get_diffs(entry, content=ondisk)
self.assertFalse(mock_open.called)
self.assertFalse(ptool._diff.called)
@@ -258,7 +242,7 @@ class TestPOSIXFile(TestPOSIXTool):
# sensitive, non-interactive -- do nothing
entry = reset()
- ptool._is_string.return_value = True
+ mock_utils.is_string.return_value = True
ptool._get_diffs(entry, sensitive=True, interactive=False)
self.assertFalse(mock_open.called)
self.assertFalse(ptool._diff.called)
diff --git a/testsuite/Testsrc/Testlib/TestUtils.py b/testsuite/Testsrc/Testlib/TestUtils.py
index 4bed67248..a37f2ecbe 100644
--- a/testsuite/Testsrc/Testlib/TestUtils.py
+++ b/testsuite/Testsrc/Testlib/TestUtils.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
import os
import sys
from Bcfg2.Utils import *
@@ -42,3 +43,17 @@ class TestPackedDigitRange(Bcfg2TestCase):
for test in exc:
self.assertNotIn(test, rng)
self.assertFalse(rng.includes(test))
+
+
+class TestIsString(Bcfg2TestCase):
+ def test_is_string(self):
+ for char in list(range(8)) + list(range(14, 32)):
+ self.assertFalse(is_string("foo" + chr(char) + "bar", 'UTF-8'))
+ for char in list(range(9, 14)) + list(range(33, 128)):
+ self.assertTrue(is_string("foo" + chr(char) + "bar", 'UTF-8'))
+
+ ustr = 'é'
+ self.assertTrue(is_string(ustr, 'UTF-8'))
+ if not inPy3k:
+ self.assertFalse(is_string("foo" + chr(128) + "bar", 'ascii'))
+ self.assertFalse(is_string(ustr, 'ascii'))