Example #1
0
 def test_import_text(self):
     import yaml
     self.filename = util.rel_to_file('import_test/parent_text.yaml')
     self.control_filename = util.rel_to_file('import_test/control_text.yaml')
     data = cfg.yaml_load_file(self.filename)
     control = cfg.yaml_load_file(self.control_filename)
     self.assertEqual(data, control)
Example #2
0
 def test_import_text(self):
     import yaml
     self.filename = util.rel_to_file('import_test/parent_text.yaml')
     self.control_filename = util.rel_to_file(
         'import_test/control_text.yaml')
     data = cfg.yaml_load_file(self.filename)
     control = cfg.yaml_load_file(self.control_filename)
     self.assertEqual(data, control)
Example #3
0
 def test_import_from_string(self):
     import yaml
     util.set_config_base_dir(util.rel_to_file('import_test'),
                              prefix=False)
     self.control_filename = util.rel_to_file('import_test/control_text.yaml')
     data = yaml.load("""
                      nothing: 0
                      child1: !text_import
                          url: file://c1_text.yaml
                      """)
     control = cfg.yaml_load_file(self.control_filename)
     self.assertEqual(data, control)
Example #4
0
 def test_import_from_string(self):
     import yaml
     util.set_config_base_dir(util.rel_to_file('import_test'), prefix=False)
     self.control_filename = util.rel_to_file(
         'import_test/control_text.yaml')
     data = yaml.load("""
                      nothing: 0
                      child1: !text_import
                          url: file://c1_text.yaml
                      """)
     control = cfg.yaml_load_file(self.control_filename)
     self.assertEqual(data, control)
Example #5
0
 def test_import(self):
     import yaml
     self.filename = util.rel_to_file('import_test/parent.yaml')
     self.control_filename = util.rel_to_file('import_test/control.yaml')
     data = cfg.yaml_load_file(self.filename)
     print repr(data)
     self.assertIn('child1', data)
     child1 = data['child1']
     self.assertIs(type(child1), dict)
     self.assertIn('child2', child1)
     child2 = child1['child2']
     self.assertIs(type(child2), dict)
     self.assertIn('dataaa', child2)
     self.assertEqual(child2['dataaa'], 'this is it')
     control = cfg.yaml_load_file(self.control_filename)
     self.assertEqual(data, control)
Example #6
0
 def test_import(self):
     import yaml
     self.filename = util.rel_to_file('import_test/parent.yaml')
     self.control_filename = util.rel_to_file('import_test/control.yaml')
     data = cfg.yaml_load_file(self.filename)
     print repr(data)
     self.assertIn('child1', data)
     child1 = data['child1']
     self.assertIs(type(child1), dict)
     self.assertIn('child2', child1)
     child2 = child1['child2']
     self.assertIs(type(child2), dict)
     self.assertIn('dataaa', child2)
     self.assertEqual(child2['dataaa'], 'this is it')
     control = cfg.yaml_load_file(self.control_filename)
     self.assertEqual(data, control)
Example #7
0
 def setUp(self):
     with open(util.rel_to_file("rediskvstore_demo.yaml"), 'r') as stream:
         self.data=yaml.load(stream)
     import uuid
     self.uuid = 'unittest-key-{0}'.format(uuid.uuid4())
     self.init()
     self.maxDiff = None
Example #8
0
 def setUp(self):
     self.filename = util.rel_to_file('test_config.yaml')
     self.ethalon = dict(setting_1=1,
                         setting_2=2,
                         complex_setting=dict(cs_1=3, cs_2=4, cs_3=5),
                         list_setting=['a', 'b', 'c'])
     self.args = cfg.DefaultYAMLConfig(self.filename)
Example #9
0
 def setUp(self):
     self.filename = util.rel_to_file('test_config.yaml')
     self.ethalon = dict(
         setting_1=1,
         setting_2=2,
         complex_setting=dict(cs_1=3, cs_2=4, cs_3=5),
         list_setting=['a', 'b', 'c']
     )
     self.args = cfg.DefaultYAMLConfig(self.filename)
Example #10
0
import occo.util.communication as comm
import occo.util.factory as factory
import occo.util as util
import occo.constants.status as nodestate
import occo.util.config as config
from occo.infobroker.uds import UDS
import occo.infobroker.rediskvstore
from functools import wraps
import uuid, sys
import io as sio
import unittest
import nose
import logging
import logging.config

CFG_FILE=util.rel_to_file('test_configuration.yaml')
TEST_CFG_FILE=util.rel_to_file('test_input.yaml')
infracfg = config.DefaultYAMLConfig(TEST_CFG_FILE)
infracfg.parse_args([])
cfg = config.DefaultYAMLConfig(CFG_FILE)
cfg.parse_args([])

logging.config.dictConfig(cfg.logging)

log = logging.getLogger()

class SingletonLocalInstruction(object):
    def __init__(self, parent_ip, **kwargs):
        self.parent_ip = parent_ip
        self.__dict__.update(kwargs)
    def perform(self):
Example #11
0
### limitations under the License.
import unittest
import occo.compiler as compiler
import yaml
import occo.util as util

def gen_case_load_dict(infra_desc):
    def test(self):
        statd = compiler.StaticDescription(infra_desc)
        self.assertEqual(yaml.load(str(statd.topological_order)),
                         infra_desc['expected_output'])
    return test
def gen_case_load_str(infra_desc):
    infra_description = yaml.dump(infra_desc)
    def test(self):
        statd = compiler.StaticDescription(infra_description)
        self.assertEqual(yaml.load(str(statd.topological_order)),
                         infra_desc['expected_output'])
    return test

class CompilerTest(unittest.TestCase):
    pass

with open(util.rel_to_file('test-config.yaml')) as f:
    config = yaml.load(f)
for isdesc in config['infrastructures']:
    setattr(CompilerTest, 'test_load_dict_{0[name]}'.format(isdesc),
            gen_case_load_dict(isdesc))
    setattr(CompilerTest, 'test_load_str_{0[name]}'.format(isdesc),
            gen_case_load_str(isdesc))
Example #12
0
 def test_cfg_param(self):
     cfg = util.config.config
     cfgfile = util.rel_to_file('comm_test_cfg.yaml', relative_cwd=True)
     abscfgfile = util.rel_to_file('comm_test_cfg.yaml', relative_cwd=False)
     c = cfg(cfg_path=cfgfile, args=[])
     self.assertEqual(c.cfg_path, abscfgfile)
Example #13
0
###
### Unless required by applicable law or agreed to in writing, software
### distributed under the License is distributed on an "AS IS" BASIS,
### WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
### See the License for the specific language governing permissions and
### limitations under the License.

import unittest
import yaml
import uuid, requests.exceptions as exc
import occo.util as util
import occo.util.config as config
import logging
import logging.config

with open(util.rel_to_file('logging.yaml')) as f:
    logging.config.dictConfig(yaml.load(f))
log = logging.getLogger('occo.test')


class DummyException(Exception):
    pass


class GeneralTest(unittest.TestCase):
    def test_i_empty(self):
        self.assertIsNone(util.icoalesce([]))

    def test_i_default(self):
        self.assertEqual(util.icoalesce([], 5), 5)
Example #14
0
 def test_python_import(self):
     import occo.exceptions as exc
     with self.assertRaises(exc.AutoImportError):
         config.yaml_load_file(util.rel_to_file('badmod.yaml'))
Example #15
0
### distributed under the License is distributed on an "AS IS" BASIS,
### WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
### See the License for the specific language governing permissions and
### limitations under the License.

import unittest
from common import *
import occo.util.config as config
import occo.infobroker as ib
import occo.infobroker.remote as rib
import threading
import logging.config
import uuid
import occo.util as util

cfg = config.DefaultYAMLConfig(util.rel_to_file('test_remote.yaml'))

logging.config.dictConfig(cfg.logging)

class RouterTest(unittest.TestCase):
    def setUp(self):
        self.provider = cfg.provider_stub
        self.cancel = threading.Event()
        mqcfg = cfg.server_mqconfig
        mqcfg['cancel_event'] = self.cancel
        self.skeleton = rib.RemoteProviderSkeleton(cfg.real_provider, mqcfg)
        self.server = threading.Thread(target=self.skeleton.consumer)
    def test_basic(self):
        with self.skeleton.consumer, self.provider.backend:
            salt = str(uuid.uuid4())
            self.server.start()
Example #16
0
 def test_load(self):
     with open(util.rel_to_file('test_router.yaml')) as f:
         provider = yaml.load(f)
     ethalon = TestRouter(sub_providers=[TestProviderA(), TestProviderB()])
     self.assertEqual(str(provider), str(ethalon), 'Loading failed')
Example #17
0
###    http://www.apache.org/licenses/LICENSE-2.0
###
### Unless required by applicable law or agreed to in writing, software
### distributed under the License is distributed on an "AS IS" BASIS,
### WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
### See the License for the specific language governing permissions and
### limitations under the License.

import occo.util.config as config
import occo.util as util
import logging
import logging.config
import occo.infobroker as ib
import occo.infraprocessor.synchronization.primitives as sp

cfg = config.DefaultYAMLConfig(util.rel_to_file('test.yaml'))

logging.config.dictConfig(cfg.logging)

log = logging.getLogger('occo.unittests')

import uuid
def uid():
    return str(uuid.uuid4())

import yaml
dummydata = yaml.load(
    """
    backends.auth_data : {}
    config_manager.aux_data : {}
    node.resource.address: null
Example #18
0
### limitations under the License.

import unittest
import occo.util as util
import occo.exceptions as exc
import occo.util.communication as comm
import occo.util.communication.mq as mq
import occo.util.config as config
import itertools as it
import threading
import logging
import logging.config
import uuid
import time

cfg = config.DefaultYAMLConfig(util.rel_to_file('comm_test_cfg.yaml'))

logging.config.dictConfig(cfg.logging)

log = logging.getLogger()

def dummy(*args, **kwargs):
    pass

class MQBootstrapTest(unittest.TestCase):
    def setUp(self):
        self.test_config = cfg.default_mqconfig
        self.fail_config_2 = dict(protocol='amqp', processor=None)
    def test_inst(self):
        list(map(lambda cls1_cls2: \
                self.assertEqual(
Example #19
0
import occo.util.communication as comm
import occo.util.factory as factory
import occo.util as util
import occo.constants.status as nodestate
import occo.util.config as config
from occo.infobroker.uds import UDS
import occo.infobroker.rediskvstore
from functools import wraps
import uuid, sys
import StringIO as sio
import unittest
import nose
import logging
import logging.config

CFG_FILE=util.rel_to_file('test_configuration.yaml')
TEST_CFG_FILE=util.rel_to_file('test_input.yaml')
infracfg = config.DefaultYAMLConfig(TEST_CFG_FILE)
infracfg.parse_args([])
cfg = config.DefaultYAMLConfig(CFG_FILE)
cfg.parse_args([])

logging.config.dictConfig(cfg.logging)

log = logging.getLogger()

class SingletonLocalInstruction(object):
    def __init__(self, parent_ip, **kwargs):
        self.parent_ip = parent_ip
        self.__dict__.update(kwargs)
    def perform(self):
Example #20
0
 def test_rel_to_file(self):
     # TODO 1) this is not a test
     #      2) need to test d_stack_frame too
     print(util.rel_to_file('test.yaml'))
Example #21
0
 def test_python_import(self):
     import occo.exceptions as exc
     with self.assertRaises(exc.AutoImportError):
         config.yaml_load_file(util.rel_to_file('badmod.yaml'))
Example #22
0
 def test_yaml(self):
     data = util.config.yaml_load_file(
         util.rel_to_file('factory_test.yaml'))
     self.assertIs(type(data['testbackend']), TestFactoryImp)
     self.assertEqual(data['testbackend'].x, 1)
Example #23
0
### limitations under the License.

import unittest
import occo.util as util
import occo.exceptions as exc
import occo.util.communication as comm
import occo.util.communication.mq as mq
import occo.util.config as config
import itertools as it
import threading
import logging
import logging.config
import uuid
import time

cfg = config.DefaultYAMLConfig(util.rel_to_file('comm_test_cfg.yaml'))

logging.config.dictConfig(cfg.logging)

log = logging.getLogger()

def dummy(*args, **kwargs):
    pass

class MQBootstrapTest(unittest.TestCase):
    def setUp(self):
        self.test_config = cfg.default_mqconfig
        self.fail_config_2 = dict(protocol='amqp', processor=None)
    def test_inst(self):
        map(lambda (cls1, cls2): \
                self.assertEqual(
Example #24
0
    def test(self):
        statd = compiler.StaticDescription(infra_desc)
        self.assertEqual(yaml.load(str(statd.topological_order)),
                         infra_desc['expected_output'])

    return test


def gen_case_load_str(infra_desc):
    infra_description = yaml.dump(infra_desc)

    def test(self):
        statd = compiler.StaticDescription(infra_description)
        self.assertEqual(yaml.load(str(statd.topological_order)),
                         infra_desc['expected_output'])

    return test


class CompilerTest(unittest.TestCase):
    pass


with open(util.rel_to_file('test-config.yaml')) as f:
    config = yaml.load(f)
for isdesc in config['infrastructures']:
    setattr(CompilerTest, 'test_load_dict_{0[name]}'.format(isdesc),
            gen_case_load_dict(isdesc))
    setattr(CompilerTest, 'test_load_str_{0[name]}'.format(isdesc),
            gen_case_load_str(isdesc))
Example #25
0
### distributed under the License is distributed on an "AS IS" BASIS,
### WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
### See the License for the specific language governing permissions and
### limitations under the License.

import unittest
from common import *
import occo.util as util
import occo.exceptions as exc
import occo.util.config as config
import occo.infobroker.kvstore as kvs
import threading
import logging.config
import uuid

cfg = config.DefaultYAMLConfig(util.rel_to_file('test_kvstore.yaml'))

logging.config.dictConfig(cfg.logging)

class KVSTest(unittest.TestCase):
    def test_inst_good(self):
        self.assertEqual(kvs.KeyValueStore.instantiate(protocol='dict').__class__,
                         kvs.DictKVStore)
    def test_inst_bad(self):
        with self.assertRaises(exc.ConfigurationError):
            p = kvs.KeyValueStore.instantiate(protocol='nonexistent')
    def test_dict_set_1(self):
        p = kvs.KeyValueStore.instantiate(protocol='dict')
        p.set_item('alma', 'korte')
    def test_dict_get_1(self):
        p = kvs.KeyValueStore.instantiate(protocol='dict')
Example #26
0
 def test_cfg_args(self):
     cfg = util.config.config
     c = cfg(args=['--cfg',
                   util.rel_to_file('comm_test_cfg.yaml',
                                    relative_cwd=True)])
Example #27
0
###
### Unless required by applicable law or agreed to in writing, software
### distributed under the License is distributed on an "AS IS" BASIS,
### WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
### See the License for the specific language governing permissions and
### limitations under the License.

import unittest
import yaml
import uuid, requests.exceptions as exc
import occo.util as util
import occo.util.config as config
import logging
import logging.config

with open(util.rel_to_file('logging.yaml')) as f:
    logging.config.dictConfig(yaml.load(f))
log = logging.getLogger('occo.test')

class DummyException(Exception):
    pass

class GeneralTest(unittest.TestCase):
    def test_i_empty(self):
        self.assertIsNone(util.icoalesce([]))
    def test_i_default(self):
        self.assertEqual(util.icoalesce([], 5), 5)
    def test_i_first(self):
        self.assertEqual(util.icoalesce(('first', None, 'third')), 'first')
    def test_i_third(self):
        self.assertEqual(util.icoalesce((None, None, 'third')), 'third')
Example #28
0
 def test_cfg_args(self):
     cfg = util.config.config
     c = cfg(args=[
         '--cfg',
         util.rel_to_file('comm_test_cfg.yaml', relative_cwd=True)
     ])
Example #29
0
 def test_rel_to_file(self):
     # TODO 1) this is not a test
     #      2) need to test d_stack_frame too
     print util.rel_to_file('test.yaml')
Example #30
0
 def test_cfg_param(self):
     cfg = util.config.config
     cfgfile = util.rel_to_file('comm_test_cfg.yaml', relative_cwd=True)
     abscfgfile = util.rel_to_file('comm_test_cfg.yaml', relative_cwd=False)
     c = cfg(cfg_path=cfgfile, args=[])
     self.assertEqual(c.cfg_path, abscfgfile)