def __init__(self, rcfile=None): """ Configuration constructor taking as argument: rcfile -- Path string to the configuration file (default: __BASEDIR__/main.conf, which can be locally overridden by __PWD__/main.conf) """ self.config = {} rcfile_found = False # If no rcfile is provided, we read __BASEDIR__/main.conf, # which can be overriden by your local share/YourProject/main.conf if rcfile is None: try: self.__parse_rc_file(Armando.get_base_dir() + os.sep + 'main.conf') rcfile_found = True self.__parse_rc_file(os.getcwd() + os.sep + 'main.conf') except FileNotFoundError as e: if rcfile_found is False: raise e else: self.__parse_rc_file(rcfile) if len(self.config.items()) == 0: raise RuntimeError( \ 'No configuration has been loaded - both %s/main.conf and ./main.conf files' \ 'were not found or are invalid' % (Armando.get_base_dir()))
def __init__(self, rcfile=None): """ Initialize the mock by using the MPD port specified in: rcfile -- Configuration file containing mpd.port (default: __TESTS_DIR__/conf/main.test.conf) """ super(MpdServerMock, self).__init__() if rcfile is None: rcfile = Armando.get_tests_dir() \ + os.sep + 'conf' \ + os.sep + 'main.test.conf' self.__config = Config(rcfile) if self.__config.get('mpd.port') is not None: self.__port = int(self.__config.get('mpd.port')) else: raise AttributeError('The configuration file %s has no mpd.port setting' % rcfile) self.__state = 'stop'
def __get_logfile_name(self): return self.__config.get('logger.logfile') or \ Armando.get_logs_dir() + os.sep + 'default.log'
import os, socket, sys, threading, time from __init__ import Armando sys.path = [Armando.get_lib_dir()] + sys.path from config import Config class MpdServerMock(threading.Thread): """ Mocks an MPD server for the predefined calls performed by unit tests @author: Fabio "BlackLight" Manganiello <*****@*****.**> """ __header_str = 'OK MPD 0.19.0\n' __footer_str = 'OK\n\n' __track = { 'file': 'spotify:track:79kQqGkJheGjmieG0qOhpu', 'Time': '342', 'Artist': 'Miles Davis', 'Album': 'Amandla', 'Title': 'Mr. Pastorius', 'Date': '1989', 'Track': '8', 'Pos': '41', 'Id': '84', 'AlbumArtist': 'Miles Davis', 'X-AlbumUri': 'spotify:album:0fabOosWong8kopy57JitO', } __status = { 'volume': '100',