tests: add some more helper function tests.
parent
1119f24071
commit
1555f23215
@ -0,0 +1,40 @@
|
||||
|
||||
import logging
|
||||
import subprocess
|
||||
import time
|
||||
import zlib
|
||||
|
||||
import unittest2
|
||||
|
||||
import testlib
|
||||
import mitogen.master
|
||||
import mitogen.parent
|
||||
import mitogen.utils
|
||||
|
||||
|
||||
class ConstructorTest(testlib.TestCase):
|
||||
klass = mitogen.core.Error
|
||||
|
||||
def test_literal_no_format(self):
|
||||
e = self.klass('error')
|
||||
self.assertEquals(e.args[0], 'error')
|
||||
self.assertTrue(isinstance(e.args[0], mitogen.core.UnicodeType))
|
||||
|
||||
def test_literal_format_chars_present(self):
|
||||
e = self.klass('error%s')
|
||||
self.assertEquals(e.args[0], 'error%s')
|
||||
self.assertTrue(isinstance(e.args[0], mitogen.core.UnicodeType))
|
||||
|
||||
def test_format(self):
|
||||
e = self.klass('error%s', 123)
|
||||
self.assertEquals(e.args[0], 'error123')
|
||||
self.assertTrue(isinstance(e.args[0], mitogen.core.UnicodeType))
|
||||
|
||||
def test_bytes_to_unicode(self):
|
||||
e = self.klass(mitogen.core.b('error'))
|
||||
self.assertEquals(e.args[0], 'error')
|
||||
self.assertTrue(isinstance(e.args[0], mitogen.core.UnicodeType))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest2.main()
|
@ -0,0 +1,40 @@
|
||||
|
||||
import mock
|
||||
import unittest2
|
||||
|
||||
import mitogen.core
|
||||
import mitogen.parent
|
||||
|
||||
import testlib
|
||||
|
||||
|
||||
class HasParentAuthorityTest(testlib.TestCase):
|
||||
func = staticmethod(mitogen.core.has_parent_authority)
|
||||
|
||||
def call(self, auth_id):
|
||||
msg = mitogen.core.Message(auth_id=auth_id)
|
||||
return self.func(msg)
|
||||
|
||||
@mock.patch('mitogen.context_id', 5555)
|
||||
@mock.patch('mitogen.parent_ids', [111, 222])
|
||||
def test_okay(self):
|
||||
self.assertFalse(self.call(0))
|
||||
self.assertTrue(self.call(5555))
|
||||
self.assertTrue(self.call(111))
|
||||
|
||||
|
||||
class IsImmediateChildTest(testlib.TestCase):
|
||||
func = staticmethod(mitogen.core.has_parent_authority)
|
||||
|
||||
def call(self, auth_id, remote_id):
|
||||
msg = mitogen.core.Message(auth_id=auth_id)
|
||||
stream = mock.Mock(remote_id=remote_id)
|
||||
return self.func(msg, stream)
|
||||
|
||||
def test_okay(self):
|
||||
self.assertFalse(0, 1)
|
||||
self.assertTrue(1, 1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest2.main()
|
Loading…
Reference in New Issue