コード例 #1
0
def test_yaml_schema(yaml_validator, yaml_stream, expected_status):
    """After loading from YAML, the validator correctly validates the structure."""

    document = yaml.load(yaml_stream)
    status = yaml_validator.validate(document)

    # Echo status for debugging
    print('=== Document ===', yaml.dump(yaml_validator.document), sep='\n')
    print('=== Errors ===', yaml.dump(yaml_validator.errors), sep='\n')

    assert status == expected_status
コード例 #2
0
def test_yaml_datetime():
    """Custom datetime serialization works as expected?"""

    now = datetime.now(tz=timezone.utc)

    assert now.isoformat() in yaml.dump(now)
    assert yaml.load(now.isoformat()) == now
コード例 #3
0
def test_file_yaml(date: datetime):
    """Does the dumping and loading of File to/from YAML works?"""

    EXPECT_FILE = addon.File(
        id=42,
        mod=addon.Mod(id=42, name='Test mod', summary='Testing'),
        name='test.jar',
        date=date,
        release=addon.Release['Beta'],
        url='https://example.com/test.jar',
        dependencies=[],
    )
    EXPECT_YAML = """
        !modfile
        file:
            date: 2017-01-01T00:42:00+00:00
            dependencies: []
            id: 42
            name: test.jar
            release: Beta
            url: https://example.com/test.jar
        id: 42
        name: Test mod
        summary: Testing
    """

    assert yaml.load(yaml.dump(EXPECT_FILE)) == EXPECT_FILE
    assert yaml.load(EXPECT_YAML) == EXPECT_FILE
コード例 #4
0
def test_release_and_yaml():
    """Serialization of Release to YAML works as intended?"""

    data = [addon.Release['Alpha']]
    text = '- Alpha\n'

    assert yaml.dump(data) == text
    assert yaml.load(text) == data
コード例 #5
0
def test_auth_loading(dummy_auth):
    """Is the authentication properly loaded from file?"""

    correct = StringIO(yaml.dump(attr.asdict(dummy_auth)))
    empty = StringIO()

    assert proxy.Authorization.load(correct) == dummy_auth

    with pytest.raises(exceptions.InvalidStream):
        proxy.Authorization.load(empty)
コード例 #6
0
def invalid_yaml(valid_pack) -> StringIO:
    """Invalid YAML mod-pack strucutre: missing path"""

    structure = {
        'game': valid_pack.game,
        'files': {
            'mods': list(valid_pack.mods.values()),
            'dependencies': list(valid_pack.dependencies.values()),
        },
    }

    return StringIO(yaml.dump(structure))
コード例 #7
0
def valid_yaml(valid_pack) -> StringIO:
    """Valid YAML mod-pack structure."""

    structure = {
        'game': valid_pack.game,
        'files': {
            'path': str(valid_pack.path),
            'mods': list(valid_pack.mods.values()),
            'dependencies': list(valid_pack.dependencies.values()),
        },
    }

    return StringIO(yaml.dump(structure))
コード例 #8
0
def gamedb() -> Path:
    """Mock supported game database file."""

    file_path = '/gamedb.yaml'
    file_contents = {
        'minecraft': dict(id=432, version='DEFAULT'),
    }

    fs = fake_filesystem.FakeFilesystem(path_separator='/')
    pathlib = fake_pathlib.FakePathlibModule(fs)

    fs.CreateFile(file_path,
                  contents=yaml.dump(file_contents),
                  encoding='utf-8')
    return pathlib.Path(file_path)
コード例 #9
0
def test_game_yaml(monkeypatch, minecraft, gamedb):
    """Does the YAML serialization work as expected?"""

    EXPECT_YAML = '''
    !game
    name: Minecraft
    version: SELECTED
    '''

    monkeypatch.setattr(curse.Game, 'find',
                        partial(curse.Game.find, gamedb=gamedb))

    roundtrip = yaml.load(yaml.dump(minecraft))
    manual = yaml.load(EXPECT_YAML)

    assert roundtrip == minecraft
    assert manual.id == minecraft.id
    assert manual.version == 'SELECTED'
コード例 #10
0
def test_yaml_path():
    """Custom path serialization working as expected?"""

    path = Path('some/long/path')

    assert str(path) in yaml.dump(path)