]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test: add unit tests for daemonperf formatting 3615/head
authorJohn Spray <john.spray@redhat.com>
Mon, 23 Feb 2015 12:28:32 +0000 (12:28 +0000)
committerJohn Spray <john.spray@redhat.com>
Thu, 5 Mar 2015 20:17:37 +0000 (20:17 +0000)
Signed-off-by: John Spray <john.spray@redhat.com>
src/test/Makefile.am
src/test/pybind/test_ceph_daemon.py [new file with mode: 0755]

index df505629944caf3110f142d4de91e9b3f2435a57..b6dcecba8fb4637810b60f8417abbcdadfbfd29a 100644 (file)
@@ -683,6 +683,7 @@ unittest_bit_vector_LDADD = $(UNITTEST_LDADD) $(CEPH_GLOBAL)
 check_PROGRAMS += unittest_bit_vector
 
 check_SCRIPTS += test/pybind/test_ceph_argparse.py
+check_SCRIPTS += test/pybind/test_ceph_daemon.py
 
 if WITH_RADOSGW
 ceph_test_cors_SOURCES = test/test_cors.cc
diff --git a/src/test/pybind/test_ceph_daemon.py b/src/test/pybind/test_ceph_daemon.py
new file mode 100755 (executable)
index 0000000..4b2a27a
--- /dev/null
@@ -0,0 +1,39 @@
+#!/usr/bin/nosetests --nocapture
+# -*- mode:python; tab-width:4; indent-tabs-mode:t -*-
+# vim: ts=4 sw=4 smarttab expandtab
+#
+"""
+Copyright (C) 2015 Red Hat
+
+This is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License version 2, as published by the Free Software
+Foundation.  See file COPYING.
+"""
+
+from StringIO import StringIO
+
+from unittest import TestCase
+
+from ceph_daemon import DaemonWatcher
+
+
+class TestDaemonWatcher(TestCase):
+    def test_format(self):
+        dw = DaemonWatcher(None)
+
+        self.assertEqual(dw.format_dimless(1, 4), "  1 ")
+        self.assertEqual(dw.format_dimless(1000, 4), "1.0k")
+        self.assertEqual(dw.format_dimless(3.14159, 4), "  3 ")
+        self.assertEqual(dw.format_dimless(1400000, 4), "1.4M")
+
+    def test_col_width(self):
+        dw = DaemonWatcher(None)
+
+        self.assertEqual(dw.col_width("foo"), 4)
+        self.assertEqual(dw.col_width("foobar"), 6)
+
+    def test_supports_color(self):
+        dw = DaemonWatcher(None)
+        # Can't count on having a tty available during tests, so only test the false case
+        self.assertEqual(dw.supports_color(StringIO()), False)