Ejemplo n.º 1
0
def test_millis_since_last_command_resets_each_command():

    rw = RunwayModel()

    @rw.command('test_command',
                inputs={'input': number},
                outputs={'output': text})
    def test_command(model, inputs):
        pass

    rw.run(debug=True)

    client = get_test_client(rw)

    assert get_manifest(client)['millisSinceLastCommand'] is None
    client.post('test_command', json={'input': 5})

    first_time = get_manifest(client)['millisSinceLastCommand']
    assert type(first_time) == int

    for i in range(5):
        sleep(0.02)
        millis_since_last_command = get_manifest(
            client)['millisSinceLastCommand']
        assert millis_since_last_command > first_time
        client.post('test_command', json={'input': 5})
        assert get_manifest(
            client)['millisSinceLastCommand'] < millis_since_last_command
Ejemplo n.º 2
0
def test_millis_since_run_increases_over_time():

    rw = RunwayModel()
    client = get_test_client(rw)
    rw.run(debug=True)

    last_time = get_manifest(client)['millisRunning']
    assert type(last_time) == int
    for i in range(3):
        sleep(0.01)
        millis_running = get_manifest(client)['millisRunning']
        assert millis_running > last_time
        last_time = millis_running
Ejemplo n.º 3
0
    def __init__(self, reader, writer, token):
        self.manifest_data = utils.get_manifest()
        self.config_data = utils.get_config()

        super().__init__(Platform(self.manifest_data['platform']),
                         self.manifest_data['version'], reader, writer, token)
        self.games: List[utils.DolphinGame] = []
Ejemplo n.º 4
0
    def onStart(self, e):
        path = self.dirpicker.GetPath()
        raw_url = self.urlinput.GetValue()
        isvalid = True
        msg = ""
        manifest = utils.get_manifest(raw_url)
        if path == "":
            isvalid = False
            msg = "A directory must be selected!"
        elif not os.path.exists(path):
            isvalid = False
            msg = "\"{}\" does not exist!".format(path)
        elif not os.path.isdir(path):
            isvalid = False
            msg = "\"{}\" is not a directory!".format(path)
        elif manifest is None:
            isvalid = False
            msg = "Could not download IIIF Presentation Manifest at URL!"
        elif len(manifest.sequences) == 0:
            isvalid = False
            msg = "No sequences in this manifest!"

        if not isvalid:
            msgdlg = wx.MessageDialog(self,
                                      msg,
                                      caption="IIIF Downloader - Error!",
                                      style=wx.OK | wx.CENTRE | wx.ICON_ERROR)
            msgdlg.ShowModal()
        else:
            path = os.path.join(path, manifest.label)
            path = utils.unique_filename(path, "")
            os.makedirs(path)
            sequence = manifest.sequences[0]
            canvases = sequence.canvases

            progressstr = "Downloading Canvas {} of {}"
            progressdlg = wx.ProgressDialog(
                title="Downloading \"{}\"".format(manifest.label),
                message="Starting...",
                maximum=len(canvases),
                style=wx.PD_CAN_ABORT | wx.PD_ELAPSED_TIME)

            for canvas, num in zip(canvases, range(len(canvases))):
                ok, _ = progressdlg.Update(num,
                                           newmsg=progressstr.format(
                                               num + 1, len(canvases)))
                if not ok:
                    break
                runthread = Thread(target=utils.download_canvas,
                                   args=(canvas, path, "{}_".format(num)))
                runthread.start()
                while runthread.is_alive():
                    progressdlg.Update(num)
                    runthread.join(0.200)

            progressdlg.Destroy()

        print("Pressed")
Ejemplo n.º 5
0
def test_gpu_in_manifest_gpu_env_false():

    rw = RunwayModel()
    rw.run(debug=True)

    client = get_test_client(rw)

    os.environ['GPU'] = '0'
    assert get_manifest(client)['GPU'] == False
Ejemplo n.º 6
0
def test_gpu_in_manifest_no_env_set():

    rw = RunwayModel()
    rw.run(debug=True)

    client = get_test_client(rw)

    if os.environ.get('GPU') is not None:
        del os.environ['GPU']

    assert get_manifest(client)['GPU'] == False
Ejemplo n.º 7
0
def print_versions():
    utils.fetch_manifest(erase=True)
    manifest = utils.get_manifest()

    latest_release = manifest['latest']['release']
    latest_snapshot = manifest['latest']['snapshot']
    # print(latest_release, latest_snapshot)

    release_data = None
    snapshot_data = None

    vs = []
    newest_version = []

    for version in manifest['versions']:
        vid = version['id']
        if vid == latest_release:
            release_data = version
        if vid == latest_snapshot:
            snapshot_data = version

        if version['type'] == 'release':
            vs.append(c.OKGREEN + vid + c.RESET)
        else:
            vs.append(vid)

    latest_rel_time = release_data['releaseTime']
    latest_snap_time = snapshot_data['releaseTime']

    pb = [
        'LATEST:', f'\trelease {latest_release} ({latest_rel_time})',
        f'\tsnapshot {latest_snapshot} ({latest_snap_time})', 'HISTORY:',
        f'\t{", ".join(vs)}'
    ]

    # print(manifest)
    print('\n'.join(pb))
    output.add_argument(
        '-o',
        '--output-dir',
        help="Directory to output to. Default is GOG installed folder",
        default=GOG_DIR)
    output.add_argument('-z',
                        '--zip',
                        action='store_true',
                        help="Output a zip to current dir for github release")
    output.add_argument('-c',
                        '--clear-logs',
                        action='store_true',
                        help="If set, attempts to remove log files")
    args = parser.parse_args()

    base_manifest = utils.get_manifest()

    if args.output_dir is not None and not args.zip:
        base_dir = args.output_dir
    else:
        base_dir = base_manifest["name"]

    if args.clear_logs:
        print("Removing log files")
        for f in [
                f'{LOG_DIR}/plugin-{gamecube["platform"]}-{gamecube["guid"]}.log',
                f'{LOG_DIR}/plugin-{wii["platform"]}-{gamecube["guid"]}.log',
                f'{LOG_DIR}/GalaxyClient.log'
        ]:
            try:
                os.remove(f)
Ejemplo n.º 9
0
def test_model_setup_and_command():

    # use a dict to share state across function scopes. This makes up for the
    # fact that Python 2.x doesn't have support for the 'nonlocal' keyword.
    closure = dict(setup_ran = False, command_ran = False)

    expected_manifest = {
        'modelSDKVersion': model_sdk_version,
        'millisRunning': None,
        'millisSinceLastCommand': None,
        'GPU': os.environ.get('GPU', False),
        'options': [{
            'type': 'category',
            'name': 'size',
            'oneOf': ['big', 'small'],
            'default': 'big',
            'description': 'The size of the model. Bigger is better but also slower.',
        }],
        'commands': [{
            'name': 'test_command',
            'description': None,
            'inputs': [{
                'type': 'text',
                'name': 'input',
                'description': 'Some input text.',
                'default': '',
                'minLength': 0
            }],
            'outputs': [{
                'type': 'number',
                'name': 'output',
                'description': 'An output number.',
                'default': 0,
                'min': 0,
                'max': 1,
                'step': 1
            }]
        }]
    }

    rw = RunwayModel()

    description = 'The size of the model. Bigger is better but also slower.'
    @rw.setup(options={ 'size': category(choices=['big', 'small'], description=description) })
    def setup(opts):
        closure['setup_ran'] = True
        return {}

    inputs = { 'input': text(description='Some input text.') }
    outputs = { 'output': number(description='An output number.') }

    # Python 2.7 doesn't seem to handle emoji serialization correctly in JSON,
    # so we will only test emoji serialization/deserialization in Python 3
    if sys.version_info[0] < 3:
        description = 'Sorry, Python 2 doesn\'t support emoji very well'
    else:
        description = 'A test command whose description contains emoji 🕳'
    expected_manifest['commands'][0]['description'] = description

    @rw.command('test_command', inputs=inputs, outputs=outputs, description=description)
    def test_command(model, opts):
        closure['command_ran'] = True
        return 100

    rw.run(debug=True)

    client = get_test_client(rw)

    response = client.get('/meta')
    assert response.is_json

    manifest = json.loads(response.data)

    # unset millisRunning as we can't reliably predict this value.
    # testing that it is an int should be good enough.
    assert type(manifest['millisRunning']) == int
    manifest['millisRunning'] = None

    assert manifest == expected_manifest

    # TEMPORARILY CHECK / PATH IN ADDITION TO /meta ----------------------------
    # ... sorry for the gross dupe code ;)
    response = client.get('/')
    assert response.is_json

    manifest = json.loads(response.data)

    # unset millisRunning as we can't reliably predict this value.
    # testing that it is an int should be good enough.
    assert type(manifest['millisRunning']) == int
    manifest['millisRunning'] = None

    assert manifest == expected_manifest
    # --------------------------------------------------------------------------

    # check the input/output manifest for GET /test_command
    response = client.get('/test_command')
    assert response.is_json

    command_manifest = json.loads(response.data)
    assert command_manifest == expected_manifest['commands'][0]

    post_data = {
        'input': 'test input'
    }
    response = client.post('/test_command', json=post_data)
    assert response.is_json
    assert json.loads(response.data) == { 'output' : 100 }

    # now that we've run a command lets make sure millis since last command is
    # a number
    manifest_after_command = get_manifest(client)
    assert type(manifest_after_command['millisSinceLastCommand']) == int

    assert closure['command_ran'] == True
    assert closure['setup_ran'] == True