[PATCH 3/3] Add test cases for the new Size class.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: David Cantrell <dcantrell@xxxxxxxxxx>

---
 tests/storage_test/Makefile.am  |    6 +++
 tests/storage_test/size_test.py |   86 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+), 0 deletions(-)
 create mode 100755 tests/storage_test/size_test.py

diff --git a/tests/storage_test/Makefile.am b/tests/storage_test/Makefile.am
index 51bb6af..e734b42 100644
--- a/tests/storage_test/Makefile.am
+++ b/tests/storage_test/Makefile.am
@@ -19,5 +19,11 @@
 
 SUBDIRS = devicelibs_test
 
+EXTRA_DIST = *.py
 
 MAINTAINERCLEANFILES = Makefile.in
+
+ANACDIR = $(top_builddir)/pyanaconda
+TESTS_ENVIRONMENT = PATH=/sbin:/usr/sbin:$$PATH PYTHONPATH=$(top_builddir)/tests:$(ANACDIR)/isys/.libs:$(ANACDIR):$(top_builddir)
+
+TESTS = size_test.py
diff --git a/tests/storage_test/size_test.py b/tests/storage_test/size_test.py
new file mode 100755
index 0000000..4f002f2
--- /dev/null
+++ b/tests/storage_test/size_test.py
@@ -0,0 +1,86 @@
+#!/usr/bin/python
+#
+# tests/storage/size_tests.py
+# Size test cases for the pyanaconda.storage module
+#
+# Copyright (C) 2010  Red Hat, Inc.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions of
+# the GNU General Public License v.2, or (at your option) any later version.
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY expressed or implied, including the implied warranties of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
+# Public License for more details.  You should have received a copy of the
+# GNU General Public License along with this program; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
+# source code or documentation are not subject to the GNU General Public
+# License and may only be used or replicated with the express permission of
+# Red Hat, Inc.
+#
+# Red Hat Author(s): David Cantrell <dcantrell@xxxxxxxxxx>
+
+import unittest
+
+from pyanaconda import anaconda_log
+anaconda_log.init()
+from pyanaconda.storage.errors import *
+from pyanaconda.storage.size import Size, _prefixes
+
+class SizeTestCase(unittest.TestCase):
+    def testExceptions(self):
+        self.assertRaises(SizeParamsError, Size)
+        self.assertRaises(SizeParamsError, Size, bytes=500, spec="45GB")
+
+        self.assertRaises(SizeNotPositiveError, Size, bytes=-1)
+
+        self.assertRaises(SizeNotPositiveError, Size, spec="0")
+        self.assertRaises(SizeNotPositiveError, Size, spec="-1 TB")
+        self.assertRaises(SizeNotPositiveError, Size, spec="-47kb")
+
+        s = Size(bytes=500)
+        self.assertRaises(SizePlacesError, s.humanReadable, places=0)
+
+    def _prefixTestHelper(self, bytes, factor, prefix, abbr):
+        c = bytes * factor
+
+        s = Size(bytes=c)
+        self.assertEquals(s, c)
+
+        if prefix:
+            u = "%sbytes" % prefix
+            s = Size(spec="%ld %s" % (bytes, u))
+            self.assertEquals(s, c)
+            self.assertEquals(s.convertTo(spec=u), bytes)
+
+        if abbr:
+            u = "%sb" % abbr
+            s = Size(spec="%ld %s" % (bytes, u))
+            self.assertEquals(s, c)
+            self.assertEquals(s.convertTo(spec=u), bytes)
+
+        if not prefix and not abbr:
+            s = Size(spec="%ld" % bytes)
+            self.assertEquals(s, c)
+            self.assertEquals(s.convertTo(), bytes)
+
+    def testPrefixes(self):
+        bytes = 47L
+        self._prefixTestHelper(bytes, 1, None, None)
+
+        for factor, prefix, abbr in _prefixes:
+            self._prefixTestHelper(bytes, factor, prefix, abbr)
+
+    def testHumanReadable(self):
+        s = Size(bytes=58929971L)
+        self.assertEquals(s.humanReadable(), "58.9 Mb")
+
+        s = Size(bytes=478360371L)
+        self.assertEquals(s.humanReadable(), "0.48 Gb")
+
+def suite():
+    return unittest.TestLoader().loadTestsFromTestCase(SizeTestCase)
+
+if __name__ == "__main__":
+    unittest.main()
-- 
1.7.2.2

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux