def test_help(self):
     """Test help output :
        -h
     """
     sys.argv = [sys.argv[0]]
     sys.argv.append('-h')
     try:
         out = StringIO()
         sys.stdout = out
         check_libvirt_stats.main()
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 3)
         output = out.getvalue().strip()
         assert output.startswith("""check_libvirt_stats""")
 def test_bad_arguments1(self):
     """Test bad arguments 1 :
        -f
     """
     sys.argv = [sys.argv[0]]
     sys.argv.append('-f')
     sys.argv.append('127.0.0.1')
     try:
         out = StringIO()
         sys.stdout = out
         check_libvirt_stats.main()
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 3)
         output = out.getvalue().strip()
         assert output.startswith("option -f not recognized")
 def test_version(self):
     """Test version output :
        -V
     """
     sys.argv = [sys.argv[0]]
     sys.argv.append('-V')
     try:
         out = StringIO()
         sys.stdout = out
         check_libvirt_stats.main()
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 3)
         output = out.getvalue().strip()
         assert output.startswith("check_libvirt_stats.py v%s" %
                                  check_libvirt_stats.PLUGIN_VERSION)
 def test_bad_arguments3(self):
     """Test bad arguments3 :
        -U GB -u test:///default
     """
     sys.argv = [sys.argv[0]]
     sys.argv.append('-U')
     sys.argv.append('MB')
     sys.argv.append('-u')
     sys.argv.append('test:///default')
     try:
         out = StringIO()
         sys.stdout = out
         check_libvirt_stats.main()
     except SystemExit, e:
         output = out.getvalue().strip()
         assert output.startswith("Argument `warning' is missing !")
 def test_fake_check(self):
     """Test fake check2 :
        -U GB -u test:///default -w 760% -c 790% 
     """
     sys.argv = [sys.argv[0]]
     sys.argv.append('-U')
     sys.argv.append('MB')
     sys.argv.append('-u')
     sys.argv.append('test:///default')
     sys.argv.append('-w')
     sys.argv.append('760')
     sys.argv.append('-c')
     sys.argv.append('800')
     try:
         out = StringIO()
         sys.stdout = out
         check_libvirt_stats.main()
     except SystemExit, e:
         output = out.getvalue().strip()
         assert output.startswith('OK')
 def test_bad_arguments4(self):
     """Test bad arguments4 :
        -U GB -u test:///default
     """
     sys.argv = [sys.argv[0]]
     sys.argv.append('-U')
     sys.argv.append('sdgsd')
     sys.argv.append('-u')
     sys.argv.append('test:///default')
     sys.argv.append('-w')
     sys.argv.append('80')
     sys.argv.append('-c')
     sys.argv.append('81')
     try:
         out = StringIO()
         sys.stdout = out
         check_libvirt_stats.main()
     except SystemExit, e:
         output = out.getvalue().strip()
         assert output.startswith("Unit : bad format !")
 def test_bad_arguments2(self):
     """Test bad arguments2 :
        -U GB -u test:///default -w 80% -c 79% 
     """
     sys.argv = [sys.argv[0]]
     sys.argv.append('-U')
     sys.argv.append('MB')
     sys.argv.append('-u')
     sys.argv.append('test:///default')
     sys.argv.append('-w')
     sys.argv.append('80')
     sys.argv.append('-c')
     sys.argv.append('79')
     try:
         out = StringIO()
         sys.stdout = out
         check_libvirt_stats.main()
     except SystemExit, e:
         output = out.getvalue().strip()
         assert output.startswith('Warning threshold must be less than')