Fix unit tests

This commit is contained in:
Andrey Pohilko 2012-09-14 15:35:36 +04:00
parent 78d43cc61c
commit 5d11916a15
9 changed files with 33 additions and 31 deletions

View File

@ -0,0 +1,3 @@
'''
Agent to be installed at remote server
'''

View File

@ -0,0 +1,3 @@
'''
Metric collection classes
'''

View File

@ -16,8 +16,8 @@ import time
import urllib2
# FIXME: don't put agent logs in current dir, place somewhere else
# FIXME: synchronize times between agent and collector better
class Config(object):
def __init__(self, config):
self.tree = etree.parse(config)

View File

@ -1,7 +1,6 @@
import unittest
from monitoring.agent.metric.custom import Custom
from MonCollector.agent.metric.custom import Custom
import time
import unittest
class Custom_TestCase(unittest.TestCase):
def setUp(self):
@ -11,47 +10,47 @@ class Custom_TestCase(unittest.TestCase):
# self.foo = None
def test_custom_(self):
custom_config={'tail': [], 'call': ['ZGlmZkV4:aWZjb25maWcgLXMgZXRoMCB8IGF3ayAnJDE9PSJldGgwIiB7cHJpbnQgJDR9Jw==:1']}
custom_config = {'tail': [], 'call': ['ZGlmZkV4:aWZjb25maWcgLXMgZXRoMCB8IGF3ayAnJDE9PSJldGgwIiB7cHJpbnQgJDR9Jw==:1']}
self.foo = Custom(**custom_config)
#self.assertEqual(x, y, "Msg");
x=self.foo.check()
x = self.foo.check()
print x
self.assertEquals(["0"], x)
time.sleep(1)
y=self.foo.check()
y = self.foo.check()
print y
assert x != y;
time.sleep(0.5)
print self.foo.check()
def test_custom_nodiff(self):
custom_config={'tail': [], 'call': ['ZGlmZkV4:aWZjb25maWcgLXMgZXRoMCB8IGF3ayAnJDE9PSJldGgwIiB7cHJpbnQgJDR9Jw==:0']}
custom_config = {'tail': [], 'call': ['ZGlmZkV4:aWZjb25maWcgLXMgZXRoMCB8IGF3ayAnJDE9PSJldGgwIiB7cHJpbnQgJDR9Jw==:0']}
self.foo = Custom(**custom_config)
x=self.foo.check()
x = self.foo.check()
print "second test", x
self.assertNotEquals(["0.0"], x)
time.sleep(1)
y=self.foo.check()
y = self.foo.check()
print y
assert x < y;
time.sleep(0.5)
z=self.foo.check()
z = self.foo.check()
print z
assert z > y;
def test_custom_fail(self):
custom_config={'tail': [], 'call': ['cXVlcnkgY291bnQ=:cXVlcnlfY2xhc3NpZnlfY2xpZW50IGZzdGF0cyB8IGdyZXAgY2xhc3MtY21kIHwgY3V0IC1mIDM=:1']}
custom_config = {'tail': [], 'call': ['cXVlcnkgY291bnQ=:cXVlcnlfY2xhc3NpZnlfY2xpZW50IGZzdGF0cyB8IGdyZXAgY2xhc3MtY21kIHwgY3V0IC1mIDM=:1']}
self.foo = Custom(**custom_config)
x=self.foo.check()
x = self.foo.check()
def test_custom_fail2(self):
custom_config={'tail': [], 'call': ['TnVtUGhyYXNlcw==:Y2F0IC92YXIvdG1wL3N0YXQx:0']}
custom_config = {'tail': [], 'call': ['TnVtUGhyYXNlcw==:Y2F0IC92YXIvdG1wL3N0YXQx:0']}
self.foo = Custom(**custom_config)
x=self.foo.check()
x = self.foo.check()
if __name__ == '__main__':
unittest.main()

View File

@ -1,7 +1,7 @@
from MonCollector.agent.metric.disk import Disk
import time
import unittest
from disk import Disk
import time
class Mem_TestCase(unittest.TestCase):
def setUp(self):
@ -10,12 +10,12 @@ class Mem_TestCase(unittest.TestCase):
def test_get(self):
print self.foo.check()
self.assertEquals(2, len(self.foo.check()))
self.assertNotEquals(['',''], self.foo.check())
self.assertNotEquals(['', ''], self.foo.check())
time.sleep(5)
self.assertNotEquals(['0','0'], self.foo.check())
self.assertNotEquals(['0', '0'], self.foo.check())
def test_cols(self):
res=self.foo.columns()
res = self.foo.columns()
self.assertEquals(['Disk_read', 'Disk_write'], res)
if __name__ == '__main__':

View File

@ -1,7 +1,6 @@
import unittest
from MonCollector.agent.metric.mem import Mem
from mem import Mem
import time
class Mem_TestCase(unittest.TestCase):
def setUp(self):

View File

@ -1,7 +1,7 @@
import unittest
from MonCollector.agent.metric.net import Net
import logging
from monitoring.agent.metric.net import Net
import time
import unittest
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s [%(levelname)s] %(name)s %(message)s")
logging.info("Begin")
@ -13,9 +13,9 @@ class Net_tcp_TestCase(unittest.TestCase):
def test_net_tcp_(self):
print self.foo.check()
self.assertEquals(2, len(self.foo.check()))
self.assertNotEquals(['',''], self.foo.check())
self.assertNotEquals(['', ''], self.foo.check())
time.sleep(2)
self.assertNotEquals(['0','0'], self.foo.check())
self.assertNotEquals(['0', '0'], self.foo.check())
if __name__ == '__main__':
unittest.main()

View File

@ -1,7 +1,6 @@
from MonCollector.agent.metric.net_tcp import NetTcp
import unittest
from monitoring.agent.metric.net_tcp import NetTcp
class Net_tcp_TestCase(unittest.TestCase):
def setUp(self):
self.foo = NetTcp()

View File

@ -1,7 +1,6 @@
import unittest
from monitoring.agent.metric.net_tx_rx import NetTxRx
from MonCollector.agent.metric.net_tx_rx import NetTxRx
import time
import unittest
class Net_tx_rx_TestCase(unittest.TestCase):
def setUp(self):