Ejemplo n.º 1
0
 def setUp(self):
     p = os.path.dirname(os.getcwd())
     p = os.path.join(p, 'CERMMorse')
     p = os.path.join(p, 'data')
     p = os.path.join(p, 'config.json')
     os.path.normpath(p)
     self.config = Config(configpath=p)
     self.config.getconfig()
     self.relay = Relay(self.config)
Ejemplo n.º 2
0
class TestConfig(TestCase):
    def setUp(self):
        self.conf = Config(configpath='../data/config.json')
        self.conf.getconfig()

    def evalcolor(self):
        color = self.conf.Color
        r = color[0]
        g = color[1]
        b = color[2]
        if (r not in range(0, 2)) | (g not in range(0, 2)) | (b not in range(
                0, 2)):
            return False
        else:
            return True

    def test_getconfig(self):

        self.assertIsInstance(self.conf.LCDPin1, int,
                              'Config LCDPin1 is not an Integer!!')
        self.assertIn(self.conf.LCDPin1, range(0, 4),
                      'Config LCDPin1 is not in I2C Range!!')
        self.assertIsInstance(self.conf.LCDPin2, int,
                              'Config LCDPin2 is not an Integer!!')
        self.assertIn(self.conf.LCDPin2, range(0, 4),
                      'Config LCDPin1 is not in I2C Range!!')
        self.assertIsInstance(self.conf.RelayPin, int,
                              'Config RelayPin is not an Integer!!')
        self.assertIn(self.conf.RelayPin, range(0, 27),
                      'Config LCDPin1 is not in GPIO Range!!')
        self.assertIsInstance(self.conf.MotionDetPin, int,
                              'Config MotionDetPin is not an Integer!!')
        self.assertIn(self.conf.MotionDetPin, range(0, 27),
                      'Config LCDPin1 is not in GPIO Range!!')
        self.assertIsInstance(self.conf.WPM, int,
                              'Config WPM is not an Integer!!')
        self.assertGreaterEqual(self.conf.WPM, 1,
                                'Config WPM is not Greater than 1!!')
        self.assertIsInstance(self.conf.MaxWPM, int,
                              'Config MaxWPM is not an Integer!!')
        self.assertGreaterEqual(
            self.conf.MaxWPM, self.conf.WPM,
            'Config MaxWPM is not Greater or Equal to WPM!!')
        self.assertLess(
            self.conf.MaxWPM, 31,
            'Config MaxWPM is Greater than 30WPM -- Seriously? !!')
        self.assertIsInstance(self.conf.SpeedAdjust, bool,
                              'Config SpeedAdjust is not Boolean!!')
        self.assertIsInstance(self.conf._Colorstr, str,
                              'Config Stored Color String is not a String!!')
        self.assertTrue(
            self.evalcolor(),
            'Parsed Color is not valid - value of number is not (0 or 1) and in form (#, #, #)'
        )
        self.assertIsInstance(self.conf.ParagraphSep, str,
                              'Config ParagraphSep is not a String!!')
Ejemplo n.º 3
0
class TestRelay(TestCase):
    def setUp(self):
        p = os.path.dirname(os.getcwd())
        p = os.path.join(p, 'CERMMorse')
        p = os.path.join(p, 'data')
        p = os.path.join(p, 'config.json')
        os.path.normpath(p)
        self.config = Config(configpath=p)
        self.config.getconfig()
        self.relay = Relay(self.config)

    def test_fire(self):
        self.relay.fire(1)

    def test_pause(self):
        self.relay.pause(.25)

    def test_both(self):
        self.test_fire()
        self.test_pause()
        self.test_fire()
        self.test_pause()
        self.test_fire()
Ejemplo n.º 4
0
    def __init__(self, logger_name="framwork"):
        self.logger = logging.getLogger(logger_name)
        logging.root.setLevel(logging.NOTSET)
        logConfig = Config().get("log")
        self.log_file_name = logConfig.get(
            "file_name"
        ) if logConfig and logConfig.get("file_name") else "test.log"
        logConfig.get("backup") if logConfig and logConfig.get("backup") else 5
        #日志的输出级别
        self.console_output_level = logConfig.get(
            'console_level'
        ) if logConfig and logConfig.get('console_level') else 'WARNING'
        self.file_output_level = logConfig.get(
            'file_level'
        ) if logConfig and logConfig.get('file_level') else 'DEBUG'
        # 日志输出格式
        pattern = logConfig.get('pattern') if logConfig and logConfig.get(
            'pattern'
        ) else '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
        self.formatter = logging.Formatter(pattern)

        def get_logger(self):
            if not self.logger.handlers:
                console_handler = logging.StreamHandler()
                console_handler.setFormatter(self.formatter)
                console_handler.setLevel(self.console_output_level)
                self.logger.addHandler(console_handler)
                file_handler = TimedRotatingFileHandler(
                    filename=os.path.join(LOG_PATH, self.log_file_name),
                    when='D',
                    interval=1,
                    backupCount=self.backup_count,
                    delay=True,
                    encoding='utf-8')
                file_handler.setFormatter(self.formatter)
                file_handler.setLevel(self.file_output_level)
                self.logger.addHandler(file_handler)
            return self.logger
Ejemplo n.º 5
0
#    along with Centralized.  If not, see <https://www.gnu.org/licenses/>.
#

import os
from requests.auth import HTTPBasicAuth
import json
import sys
from readconfig import Config

if len(sys.argv) < 2:
    print("An hostname must be supplied.", file=sys.stderr)
    sys.exit(1)

hostname = sys.argv[1]

config = Config()
conf = config.getconfig()

config.load_ca()

import requests

baseurl = conf['main']['url']
uuid_path = "/.uuid_centralized"

organization_uuid = conf['main']['organization_uuid']
uuid = ""

if not os.path.exists(uuid_path):
    with open(uuid_path, 'w') as u:
        with open('/proc/sys/kernel/random/uuid', 'r') as procfile:
Ejemplo n.º 6
0
 def setUp(self):
     self.conf = Config(configpath='../data/config.json')
     self.conf.getconfig()
Ejemplo n.º 7
0
from discordtakbot import DiscordTakBot
from readconfig import Config

# Configs are attempted to be read in this order until one succeeds.
# This allows a dev to have a config that isn't checked in to the repository
CONFIG_FILES = ["botsettings.dev.json", "botsettings.json"]

if __name__ == "__main__":
    config = None
    for config_file in CONFIG_FILES:
        print(f"Attempting to read config from '{config_file}'")
        try:
            config = Config.load(config_file)
            print(f"Successfully read config from '{config_file}'")
            break
        except FileNotFoundError:
            print(
                f"Cannot read config from '{config_file}' because it does not exist'"
            )
    if not config:
        exit("Failed read configuration")

    initial_moves = [
        "a2", "a1", "b1", "a2-", "b1<", "b1", "Ca2", "b2", "a2-", "b3",
        "3a1>111"
    ]

    bot = DiscordTakBot(config.tak, initial_moves=initial_moves)
    bot.run(config.discord.token)
Ejemplo n.º 8
0
                md.pause(self.wordgap)
            elif element == '.':
                md.fire(self.dot)
                md.pause(self.gap)
            elif element == '-':
                md.fire(self.dash)
                md.pause(self.gap)
            elif element == 'X':
                md.fire(self.zerodash)
                md.pause(self.gap)
            elif element == 'L':
                md.fire(self.longdash)
                md.pause(self.gap)
            elif element == 'G':
                md.pause(self.lettergap)


if __name__ == '__main__':
    import os

    p = os.path.dirname(os.getcwd())
    p = os.path.join(p, 'CERMMorse')
    p = os.path.join(p, 'data')
    p = os.path.join(p, 'config.json')
    os.path.normpath(p)
    cnf = Config(configpath=p)
    cnf.getconfig()
    pm = PlayMorse(5, cnf)
    print(pm)
    pm.playchar("Test Message. And another Test message. , /")
 def setUp(self):
     self.config = Config(configpath='../data/config.json')
     self.det = Detector(self.config)