예제 #1
0
 def __init__(self, ini_file=None):
     self.config = configparser.ConfigParser(os.environ, allow_no_value=True)
     self.__internal__parser = configparser.ConfigParser(allow_no_value=True)
     if ini_file:
         self.config.read_file(open(ini_file))
         self.__internal__parser.read_file(open(ini_file))
     else:
         self.config.read(rf(__name__, 'etc/conf.ini'))
         self.__internal__parser.read(rf(__name__, 'etc/conf.ini'))
예제 #2
0
    def __init__(self, word_list=None):
        self.__accepted_chars = set()

        if word_list is None:
            with open(rf('wordplay', 'data/sample_wordlist.dat')) as wordlist:
                self.__word_list = set(wordlist.read().split())
        elif word_list == 'Scrabble':
            with open(rf('wordplay',
                         'data/scrabble_wordlist.dat')) as wordlist:
                self.__word_list = set(wordlist.read().split())
        elif isinstance(word_list, set):
            self.__word_list = word_list
        else:
            raise ArgumentError(ErrorMessage.TYPE_SET)
예제 #3
0
 def test_invalid_config_file(self):
     """
     Validates if FileNotFoundError is raised when loading the configuration
     """
     ConfReader.INI_FILE = rf(
         __name__, 'data/invalid_test.ini')  # Loads different ini file
     self.assertRaises(FileNotFoundError, lambda: ConfReader.get('X', 'y'))
예제 #4
0
 def setUp(self):
     """
     Initialize test case with a preconfigured ini file
     """
     ConfReader.RELOAD = True
     ConfReader.DICT_CACHE = False
     ConfReader(rf(__name__, ReaderTestCase.INI_TEST_FILE))  # The ConfReader must be initialized
예제 #5
0
파일: tal_tests.py 프로젝트: Selfnet-5G/NBI
 def create_tal(self):
     # Load file
     tal_script = ET.parse(rf(__name__, 'etc/tal.xml'))
     result = self.app.post(TALTest.ENDPOINT,
                            headers={'X-Auth-Token': self.cloud_admin},
                            params=ET.tostring(tal_script.getroot(),
                                               encoding='utf8',
                                               method='xml'))
     self.assertEqual(result.status, 201)
예제 #6
0
 def test_file_not_reloaded(self):
     """
     Validates if the configuration remain after an unsuccessfully reload operation.
     This is done by changing the file and setting the reload as False.
     """
     self.assertEqual(ConfReader.get('SECTION_1', 'config_4'), 10.5)
     ConfReader.INI_FILE = rf(
         __name__, 'data/test_file_2.ini')  # Loads different ini file
     ConfReader.RELOAD = False
     self.assertEqual(ConfReader.get('SECTION_1', 'config_4'), 10.5)
예제 #7
0
    def create_app(self):
        result = self.app.post(TestNBIAppCatalogue.ROUTE,
                               headers={'X-Auth-Token': self.cloud_admin},
                               upload_files=[('file',
                                              rf(__name__,
                                                 'etc/vnf-test.tar'))])

        self.assertTrue(result.status)
        data = json.loads(result.body.decode('utf-8'))
        self.assertTrue('app' in data)
        self.assertTrue('id' in data.get('app'))
        return data.get('app').get('id')
예제 #8
0
    def _load_schemas(self):
        schema_dir = rf('opengever.bundle', 'schemas/')
        schemas = {}
        filenames = os.listdir(schema_dir)
        for schema_filename in filenames:
            short_name = schema_filename.replace('.schema.json', '')
            if '%s.json' % short_name in BUNDLE_JSON_TYPES:
                schema_path = os.path.join(schema_dir, schema_filename)

                with codecs.open(schema_path, 'r', 'utf-8-sig') as schema_file:
                    schema = json.load(schema_file)
                schemas['%s.json' % short_name] = schema
        return schemas
예제 #9
0
    def _load_schemas(self):
        schema_dir = rf('opengever.bundle', 'schemas/')
        schemas = {}
        filenames = os.listdir(schema_dir)
        for schema_filename in filenames:
            short_name = schema_filename.replace('.schema.json', '')
            if '%s.json' % short_name in BUNDLE_JSON_TYPES:
                schema_path = os.path.join(schema_dir, schema_filename)

                with codecs.open(schema_path, 'r', 'utf-8-sig') as schema_file:
                    schema = json.load(schema_file)
                schemas['%s.json' % short_name] = schema
        return schemas
예제 #10
0
    def load_schemas(self):
        schema_dir = rf("opengever.bundle", "schemas/")
        schemas = {}
        filenames = os.listdir(schema_dir)
        for schema_filename in filenames:
            short_name = schema_filename.replace(".schema.json", "")
            if "%s.json" % short_name in BUNDLE_JSON_TYPES:
                schema_path = os.path.join(schema_dir, schema_filename)

                with codecs.open(schema_path, "r", "utf-8-sig") as schema_file:
                    schema = json.load(schema_file)
                schemas["%s.json" % short_name] = schema
        return schemas
예제 #11
0
    def test_file_reload(self, get_time):
        """
        Validates if the reload is successfully done.
        This is tested by forcing a new INI file
        """
        base_time = ConfReader.__INI_FILE_TIME__
        get_time.return_value = base_time

        self.assertEqual(ConfReader.get('SECTION_1', 'config_4'), 10.5)
        ConfReader.INI_FILE = rf(
            __name__, 'data/test_file_2.ini')  # Loads different ini file
        get_time.return_value = base_time + 15  # Force the modification time higher then the original

        self.assertEqual(ConfReader.get('SECTION_1', 'config_4'), 15)
예제 #12
0
    def setUp(self):
        super(KeystoneTestCase, self).setUp()

        # Login the necessary users
        self.cloud_admin = self.__login_user__('admin', 'SELFNET@admin',
                                               'default')
        self.tenant_user = self.__login_user__('user_nbi', 'user_nbi',
                                               'NBI_DOM_1')
        self.tenant_admin = self.__login_user__('admin_nbi', 'admin_nbi',
                                                'NBI_DOM_1')

        # Start oslo_config
        start_conf(config_location=[rf(__name__, 'etc/oslo_conf.ini')])
        self.__init_enforcer__()
예제 #13
0
    def test_unmodified_change_date_dont_reload(self, get_time=None):
        """
        Validates if the configuration remain after an unsuccessfully force reload operation.
        This is done by changing the file and setting the reload as False.
        """
        base_time = ConfReader.__INI_FILE_TIME__
        get_time.return_value = base_time

        self.assertEqual(ConfReader.get('SECTION_1', 'config_4'), 10.5)
        ConfReader.INI_FILE = rf(
            __name__, 'data/test_file_2.ini')  # Loads different ini file

        # Assert same config with RELOAD on even with file change
        self.assertEqual(
            ConfReader.get('SECTION_1', 'config_4', force_reload=True), 10.5)
예제 #14
0
    def test_reload_parameter(self, get_time):
        """
        Validates the force_reload option when the RELOAD is False.
        This is tested by forcing a new INI file
        """
        base_time = ConfReader.__INI_FILE_TIME__
        get_time.return_value = base_time

        self.assertEqual(ConfReader.get('SECTION_1', 'config_4'), 10.5)
        ConfReader.INI_FILE = rf(
            __name__, 'data/test_file_2.ini')  # Loads different ini file
        ConfReader.RELOAD = False
        get_time.return_value = base_time + 15  # Force the modification time higher then the original

        self.assertEqual(
            ConfReader.get('SECTION_1', 'config_4', force_reload=True), 15)
예제 #15
0
    def test_read_with_force_reload(self):
        """
        Test the decorator when a function as both arguments and keyword arguments.
        It validates the arguments remain unchanged.

        The config must be placed between arguments and keyword arguments.
        """
        @read_conf("SECTION_1", 'config_4')
        def read_argument(config):
            self.assertEqual(config, 10.5)

        @read_conf("SECTION_1", 'config_4', force_reload=False)
        def read_argument_force(config):
            self.assertEqual(config, 15)

        read_argument()
        ConfReader().change_config_file(rf(
            __name__, 'data/test_file_2.ini'))  # Loads different ini file
        read_argument_force()
예제 #16
0
def absolute_path(fname_in, default_path):
    """Get absolute paths for filename.

    Args:
        fname (string): filename
        test_status(boolean): This file is a pre-packaged havic datafile.

    Returns:
        valid absolute file path if it is a file, else None
    """
    fname_out = None
    if default_path:
        fname_in = rf(__parent_dir__, fname_in)
    else:
        pass
    if Path(fname_in).is_file():
        fname_out = Path(fname_in).resolve(strict=True)
    else:
        print(f"\nWarning, '{fname_in}' is not a valid file path.\n")
    return fname_out
예제 #17
0
 def setUp(self):
     self.version = __version__
     self.yaml = yaml.load(open(rf(__parent_dir__, __havic_yaml__)), Loader=yaml.FullLoader)
예제 #18
0
def get_bundle_path(bundle_name):
    return rf('opengever.bundle.tests', 'assets/%s' % bundle_name)
예제 #19
0
파일: sound.py 프로젝트: aforren1/go-no-go
    @state.setter
    def state(self, value):
        if value == 'play':
            self.play()
        elif value == 'stop':
            self.stop()
        else:
            raise ValueError('Invalid state.')
        self._state = value


if __name__ == '__main__':
    from time import sleep
    from pkg_resources import resource_filename as rf
    coin = rf('gonogo', '/resources/sound/coin.wav')
    buzz = rf('gonogo', '/resources/sound/buzz.wav')
    blop = rf('gonogo', '/resources/sound/blop.wav')
    snd = Sound.from_file(coin)
    snd5 = Sound.from_file(buzz)
    print('start')
    snd.play()
    sleep(1)
    snd.stop()
    snd2 = Sound.from_file(coin)
    snd6 = Sound.from_file(blop)

    fs = 16000
    freq = 400
    length = 0.3 * fs
    xx = np.arange(0, length)
예제 #20
0
파일: __init__.py 프로젝트: Selfnet-5G/NBI
    def setUp(self):
        self.app = TestNBIAPP(loadapp('config:' + rf(__name__, 'wsgi.ini')))

        # Login the necessary users
        self.cloud_admin = self.login_user()
예제 #21
0
 def setUp(self):
     self.PMC7259881yaml = yaml.load(open(rf(__parent_dir__, __havic_PMC7259881__)), Loader=yaml.FullLoader)
     self.detection_pipeline_PMC7259881 = Pipeline(self.PMC7259881yaml)
예제 #22
0
def get_bundle_path(bundle_name):
    return rf("opengever.bundle.tests", "assets/%s" % bundle_name)
예제 #23
0
 def setUp(self):
     self.measlesyaml = yaml.load(open(rf(__parent_dir__, __measles_wgs_yaml__)), Loader=yaml.FullLoader)
     self.detection_pipeline_measles = Pipeline(self.measlesyaml)
예제 #24
0
 def setUp(self):
     self.hivyaml = yaml.load(open(rf(__parent_dir__, __hiv_amplicon_yaml__)), Loader=yaml.FullLoader)
     self.detection_pipeline_hiv = Pipeline(self.hivyaml)
예제 #25
0
 def tearDown(self):
     #self.__execute_command__('echo "CREATE DATABASE keystone;" | mysql -u root -proot -h 127.0.0.1')
     # Restore Dump
     self.__execute_command__(
         'mysql keystone -h 127.0.01 -u root -proot < {}'.format(
             rf(__name__, 'etc/keystone_dump.sql')))
예제 #26
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import re
from pkg_resources import resource_filename as rf
from collections import defaultdict
from typing import Set, List, Dict
from chrhyme.parser import word_parser

phrase_dict = {}
with open(rf('chrhyme', 'data/phrase_dict.txt'), 'r') as f:
    for line in f:
        items = line.strip().split('\t')
        phrase_dict[tuple(items[0].split())] = items[1].split()


def generate_rhythms():
    while 1:
        user_input = input('◼︎ 请输入一个你想押韵的词(按回车退出): ')
        if user_input:
            word = prune_word(user_input)
            if word:
                num_char = len(word)

                cs = input('\t-是否押声母?例如对于"欢喜",押"还席"不押"惯技"。\n\t 请输入要押声母的字的位置\n\t (0-不押;1-押"欢";2-押"喜";12-押"欢喜"): ')
                vs = input('\t-是否押全韵母?例如对于"欢喜",押"端倪"不押"叹息"。\n\t 请输入要押全韵母的字的位置\n\t (0-不押;1-押"欢";2-押"喜";12-押"欢喜"): ')
                c_ids = check_positions(cs, num_char)
                v_ids = check_positions(vs, num_char)

                pinyins = word_parser(word)
                candidates = get_candidates(word, pinyins, num_char, c_ids, v_ids)
예제 #27
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import re
from pkg_resources import resource_filename as rf
from collections import defaultdict
from typing import Set, List, Dict
from chrhyme.parser import word_parser

phrase_dict = {}
with open(rf('chrhyme', 'data/phrase_dict.txt'), 'r', encoding="utf-8") as f:
    for line in f:
        items = line.strip().split('\t')
        phrase_dict[tuple(items[0].split())] = items[1].split()


def generate_rhythms():
    while 1:
        user_input = input('◼︎ 请输入一个你想押韵的词(按回车退出): ')
        if user_input:
            word = prune_word(user_input)
            if word:
                num_char = len(word)

                cs = input(
                    '\t-是否押声母?例如对于"欢喜",押"还席"不押"惯技"。\n\t 请输入要押声母的字的位置\n\t (0-不押;1-押"欢";2-押"喜";12-押"欢喜"): '
                )
                vs = input(
                    '\t-是否押全韵母?例如对于"欢喜",押"端倪"不押"叹息"。\n\t 请输入要押全韵母的字的位置\n\t (0-不押;1-押"欢";2-押"喜";12-押"欢喜"): '
                )
                c_ids = check_positions(cs, num_char)
예제 #28
0
 def setUp(self):
     self.app = TestNBIAPP(loadapp('config:' + rf(__name__, 'wsgi.ini')))
예제 #29
0
def get_bundle_path(bundle_name):
    return rf('opengever.bundle.tests', 'assets/%s' % bundle_name)