Пример #1
0
    def test_same_as_present(self):
        name = str(uuid.uuid4())
        assert not exists(name)
        try:
            c = Config(name)

            for i in range(100):
                v = round(random.random(), 6)
                self.assertTrue(c.set('haha', v))
                self.assertTrue(almost_equal(v, c.get('haha')))
                self.assertFalse(c.set('haha', v))
        finally:
            os.remove(name)
            assert not exists(name)
Пример #2
0
 def test_non_existent_param(self):
     """should complain on attempt to read undefined parameter"""
     name = str(uuid.uuid4())
     assert not exists(name)
     check = False
     try:
         c = Config(name)
         assert exists(name)
         c.get('haha')
     except LookupError:
         check = True
     finally:
         os.remove(name)
         assert not exists(name)
     self.assertTrue(check)
Пример #3
0
 def test_config_create_if_not_exists1(self):
     name = str(uuid.uuid4())
     assert not exists(name)
     try:
         c = Config(name, create_if_not_exists=False)
     except RuntimeError:
         pass
Пример #4
0
 def test_config_create_if_not_exists2(self):
     """create if not exists"""
     name = str(uuid.uuid4())
     assert not exists(name)
     try:
         c = Config(name)
         self.assertTrue(exists(name))
     finally:
         os.remove(name)
         assert not exists(name)
Пример #5
0
    def test_update_param(self):
        """update existing parameter"""
        name = str(uuid.uuid4())
        assert not exists(name)
        try:
            c = Config(name)
            assert exists(name)

            for i in range(100):
                v = random.random()
                c.set('haha', v)
                self.assertTrue(almost_equal(v, c.get('haha')))

                v = random.random()
                c.set('haha', v)
                self.assertTrue(almost_equal(v, c.get('haha')))
        finally:
            os.remove(name)
            assert not exists(name)
Пример #6
0
    def test_create_param(self):
        """should create param if not exists"""
        name = str(uuid.uuid4())
        assert not exists(name)
        c = Config(name)
        assert exists(name)
        check = False
        try:
            c.get('haha')
        except LookupError:
            check = True
        self.assertTrue(check)

        try:
            v = random.random()
            c.set('haha', v)
            self.assertTrue(almost_equal(v, c.get('haha')))
        finally:
            os.remove(name)
            assert not exists(name)
Пример #7
0
from twisted.python import log
from config.config_support import Config
from cred import cred

logging.basicConfig(level=logging.DEBUG)
logging.getLogger('pika').setLevel(logging.WARNING)

setDebugging(True)

nodeid = socket.gethostname()
exchange_name = 'grid_cnc'
queue_name = 'to_' + nodeid
routing_key = nodeid + '.c'
user, passwd = nodeid, cred['rabbitmq']
config_file = expanduser('~/config.db')
config = Config(config_file)


class PikaFactory(protocol.ReconnectingClientFactory):
    name = 'AMQP:Factory'

    def __init__(self, parameters):
        self.parameters = parameters
        self.client = None
        self.queued_messages = []
        self.read_list = []

    def startedConnecting(self, connector):
        log.msg('Started to connect.', system=self.name)

    def buildProtocol(self, addr):