Пример #1
0
def test_fetch_mob(fixture):
    convert = converter.Converter(api_key)
    expected_json = json.loads(
        open(fixture('mob_1002.json'), encoding='utf-8').read())
    fetched_json = convert.fetch_mob(1002)
    assert fetched_json == expected_json
    assert convert.fetch_mob(-1) == 'Id: -1, Error: Mob not found'
    convert = converter.Converter('fake-api-key')
    with pytest.raises(IOError):
        convert.fetch_mob(1002)
Пример #2
0
def test_fetch_item(fixture):
    convert = converter.Converter(api_key)
    expected_json = json.loads(
        open(fixture('item_1101.json'), encoding='utf-8').read())
    fetched_json = convert.fetch_item(1101)
    assert fetched_json == expected_json
    assert convert.fetch_item(-1) == {'Id': -1, 'Error': 'Item not found'}
    convert = converter.Converter('fake-api-key')
    with pytest.raises(IOError):
        convert.fetch_item(1101)
Пример #3
0
def item(ctx, file, sort, wrap, debug, value):
    """Converts item ids to rathena item_db.yml.

    \b
    Examples:
        # Pass API key and convert item ids 501 and 1101
        dp2rathena --api-key <your-api-key> item 501 1101
    \b
        # Pass API key and convert items via STDIN and sort result by id
        dp2rathena -k <your-api-key> item --sort -f -
    \b
        # Save API key and convert item ids in ids_to_convert.txt
        dp2rathena config
        dp2rathena item -f ids_to_convert.txt
    """
    if file:
        if len(value) != 1:
            raise click.UsageError('One file required for processing.')
        to_convert = click.open_file(value[0], 'r').read().splitlines()
    else:
        if len(value) == 0:
            raise click.UsageError('Item id required.')
        for v in value:
            if not v.isdigit():
                raise click.UsageError(f'Non-integer item id - {v}')
        to_convert = value
    api_key = ctx.obj[DP_KEY]
    click.echo(converter.Converter(api_key,
                                   debug).convert_item(to_convert, sort, wrap),
               nl=False)
Пример #4
0
def mobskill(ctx, file, comment, debug, value):
    """Converts mob ids to rathena mob_skill_db.txt.

    \b
    Examples:
        # Pass API key and convert mob ids 1002 and 1049
        dp2rathena --api-key <your-api-key> mobskill 1002 1049
    \b
        # Pass API key and convert mobs via STDIN
        dp2rathena -k <your-api-key> mobskill -f -
    \b
        # Save API key and convert mob ids in ids_to_convert.txt
        dp2rathena config
        dp2rathena mobskill -f ids_to_convert.txt
    """
    if file:
        if len(value) != 1:
            raise click.UsageError('One file required for processing.')
        to_convert = click.open_file(value[0], 'r').read().splitlines()
    else:
        if len(value) == 0:
            raise click.UsageError('Mob id required.')
        for v in value:
            if not v.isdigit():
                raise click.UsageError(f'Non-integer mob id - {v}')
        to_convert = value
    api_key = ctx.obj[DP_KEY]
    click.echo(converter.Converter(api_key, debug).convert_mob_skill(
        to_convert, comment),
               nl=False)
Пример #5
0
def test_convert_item_nonapi():
    convert = converter.Converter(api_key)
    generated_yml = convert.convert_item([], sort=False, wrap=False)
    assert generated_yml == '[]\n'
    generated_yml = convert.convert_item([], sort=True, wrap=False)
    assert generated_yml == '[]\n'
    generated_yml = convert.convert_item([], sort=False, wrap=True)
    assert generated_yml == 'Header:\n  Type: ITEM_DB\n  Version: 1\nBody: []\n'
    generated_yml = convert.convert_item([], sort=True, wrap=True)
    assert generated_yml == 'Header:\n  Type: ITEM_DB\n  Version: 1\nBody: []\n'
Пример #6
0
def test_convert_mob(fixture):
    convert = converter.Converter(api_key)
    expected = open(fixture('mob_1002.yml'), encoding='utf-8').read()
    generated = convert.convert_mob([1002])
    assert generated == expected
    expected = open(fixture('mob_1002_1049.yml'), encoding='utf-8').read()
    generated = convert.convert_mob([1002, 1049])
    assert generated == expected
    generated = convert.convert_mob([1002, '', 1049])
    assert generated == expected
    expected = open(fixture('mob_1049_1002.yml'), encoding='utf-8').read()
    generated = convert.convert_mob([1049, 1002])
    assert generated == expected
Пример #7
0
def test_convert_item(fixture):
    convert = converter.Converter(api_key)
    expected_yml = open(fixture('item_1101_nowrap.yml'),
                        encoding='utf-8').read()
    generated_yml = convert.convert_item([1101], sort=False, wrap=False)
    assert generated_yml == expected_yml
    expected_yml = open(fixture('item_501_1101_nowrap.yml'),
                        encoding='utf-8').read()
    generated_yml = convert.convert_item([1101, 501], sort=True, wrap=False)
    assert generated_yml == expected_yml
    expected_yml = open(fixture('item_501_1101.yml'), encoding='utf-8').read()
    generated_yml = convert.convert_item([501, 1101], sort=False, wrap=True)
    assert generated_yml == expected_yml
    generated_yml = convert.convert_item([1101, 501], sort=True, wrap=True)
    assert generated_yml == expected_yml
    generated_yml = convert.convert_item([501, '', 1101],
                                         sort=False,
                                         wrap=True)
    assert generated_yml == expected_yml
Пример #8
0
def test_convert_mob_skill_nonapi():
    convert = converter.Converter(api_key)
    generated_txt = convert.convert_mob_skill([])
    assert generated_txt == ''
    generated_txt = convert.convert_mob_skill([''])
    assert generated_txt == ''
Пример #9
0
def test_remove_numerical_quotes():
    convert = converter.Converter(api_key)
    result = convert.remove_numerical_quotes('\'01\'')
    assert result == '01'
    result = convert.remove_numerical_quotes('Tell\'tale')
    assert result == 'Tell\'tale'