1 #!/usr/bin/env nosetests
2 # -*- mode:python; tab-width:4; indent-tabs-mode:t -*-
3 # vim: ts=4 sw=4 smarttab expandtab
6 Copyright (C) 2015 Red Hat
8 This is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public
10 License version 2, as published by the Free Software
11 Foundation. See file COPYING.
14 from unittest import TestCase
16 from ceph_daemon import DaemonWatcher
19 from StringIO import StringIO
21 from io import StringIO
24 class TestDaemonWatcher(TestCase):
25 def test_format(self):
26 dw = DaemonWatcher(None)
28 self.assertEqual(dw.format_dimless(1, 4), " 1 ")
29 self.assertEqual(dw.format_dimless(1000, 4), "1.0k")
30 self.assertEqual(dw.format_dimless(3.14159, 4), " 3 ")
31 self.assertEqual(dw.format_dimless(1400000, 4), "1.4M")
33 def test_col_width(self):
34 dw = DaemonWatcher(None)
36 self.assertEqual(dw.col_width("foo"), 4)
37 self.assertEqual(dw.col_width("foobar"), 6)
39 def test_supports_color(self):
40 dw = DaemonWatcher(None)
41 # Can't count on having a tty available during tests, so only test the false case
42 self.assertEqual(dw.supports_color(StringIO()), False)
44 # compile-command: "cd ../.. ; make -j4 &&
45 # PYTHONPATH=pybind nosetests --stop \
46 # test/pybind/test_ceph_daemon.py