예제 #1
0
def setup_config_file(tmp_path, config_brokers, config_topic, config_params, config_file):
    cwd = Path.cwd().absolute()
    try:
        os.chdir(str(tmp_path))
        create_config_file(config_brokers, config_topic, config_params, config=config_file)
        yield
    finally:
        os.chdir(str(cwd))
예제 #2
0
def setup_bad_env_config(tmp_path, config_brokers, config_topic):
    cwd = Path.cwd().absolute()
    try:
        os.chdir(str(tmp_path))
        config = tmp_path / 'ss-config.yml'
        create_config_file(brokers=config_brokers, topic=config_topic)
        os.environ['SINETSTREAM_CONFIG_URL'] = config.as_uri()
        yield
    finally:
        del (os.environ['SINETSTREAM_CONFIG_URL'])
        os.chdir(str(cwd))
예제 #3
0
def create_topic():
    cwd = Path.cwd().absolute()
    with TemporaryDirectory() as work_dir:
        try:
            os.chdir(str(work_dir))
            create_config_file(brokers=[BROKER])
            with MessageWriter(SERVICE, TOPIC) as f:
                logger.debug(f"create topic: {TOPIC}")
                f.publish(b"message 000")
        finally:
            os.chdir(str(cwd))
예제 #4
0
def setup_home_config(tmp_path, config_brokers, config_topic):
    cwd = Path.cwd().absolute()
    config = Path('~/.config/sinetstream/config.yml').expanduser()
    backup = None
    try:
        os.chdir(str(tmp_path))
        if config.exists():
            backup = tmp_path / 'config.yml'
            copyfile(config, backup)
        else:
            config.parent.mkdir(parents=True, exist_ok=True)
        create_config_file(brokers=config_brokers,
                           topic=config_topic,
                           config=config)
        yield
    finally:
        os.chdir(str(cwd))
        if backup:
            copyfile(backup, config)
        else:
            config.unlink()