예제 #1
0
def test_schedule_with_time(monkeypatch, tmpdir):

    home = tmpdir.mkdir("current_dir")  # temporary directory for testing
    launch = tmpdir.mkdir("TestAgents")  # temporary directory for testing

    # monkeypatch directories and suppress the plist loading process
    # NOTE: it may be possible to test the plist loading process
    # but I can't work out how to do it universally / consistently

    def mock_current_dir():
        return str(home)

    def mock_home_dir_expansion(arg):
        return str(launch)

    def suppress_subprocess(args, stdout=None, stderr=None, shell=None):
        return None

    monkeypatch.setattr(os, "getcwd", mock_current_dir)
    monkeypatch.setattr(os.path, "expanduser", mock_home_dir_expansion)
    monkeypatch.setattr(subprocess, "run", suppress_subprocess)

    # now we run the function we're testing
    ephemetoot.schedule(Namespace(schedule=".", time=["10", "30"]))

    # assert the plist file was created
    plist_file = os.path.join(launch, "ephemetoot.scheduler.plist")
    assert os.path.lexists(plist_file)

    # assert that correct values were modified in the file
    f = open(plist_file, "r")
    plist = f.readlines()

    assert plist[21] == "    <integer>10</integer>\n"
    assert plist[23] == "    <integer>30</integer>\n"
예제 #2
0
def main():
    """
    Call ephemetoot.check_toots() on each user in the config file, with options set via flags from command line.
    """
    try:

        if options.init:
            func.init()
        elif options.version:
            func.version(vnum)
        elif options.schedule:
            func.schedule(options)
        else:
            if not options.quiet:
                print("")
                print("============= EPHEMETOOT v" + vnum +
                      " ================")
                print("Running at " + str(
                    datetime.now(timezone.utc).strftime(
                        "%a %d %b %Y %H:%M:%S %z")))
                print("================================================")
                print("")
            if options.test:
                print("This is a test run...\n")
            with open(config_file) as config:
                for accounts in yaml.safe_load_all(config):
                    for user in accounts:
                        func.check_toots(user, options)

    except FileNotFoundError as err:

        if err.filename == config_file:
            print("🕵️  Missing config file")
            print("Run \033[92mephemetoot --init\033[0m to create a new one\n")

        else:
            print(
                "\n🤷‍♂️  The archive directory in your config file does not exist"
            )
            print(
                "Create the directory or correct your config before trying again\n"
            )