Esempio n. 1
0
def test_rankfile_load_existing_file_with_errors(tmpdir, fffake, capsys):
    apifile = tmpdir.join('api_file.json')
    apifile.write_text(dumps({'a': 'b'}), 'utf-8')

    rf = tmpdir.join('rankfile.json')
    rf.write_text(dumps(None), 'utf-8')

    ff = fffake(apifile,
                nodelist=tmpdir.join('nodelist.json'),
                rankfile=rf,
                dry=True)
    assert _rankfile_load(ff) == (False, None)
    out, err = capsys.readouterr()
    assert 'ERROR' in out
    assert 'could' in out
    assert 'not' in out
    assert err == ''

    rf = tmpdir.join('rankfile.json')
    rf.write_text(dumps({'a': 'b'}), 'utf-8')

    ff = fffake(apifile,
                nodelist=tmpdir.join('nodelist.json'),
                rankfile=rf,
                dry=True)
    assert _rankfile_load(ff) == (False, None)
    out, err = capsys.readouterr()
    assert 'ERROR' in out
    assert 'is' in out
    assert 'no' in out
    assert err == ''

    assert tmpdir.remove() is None
Esempio n. 2
0
def test_rankfile_load_existing_file_with_errors(tmpdir, fffake, capsys):
    apifile = tmpdir.join('api_file.json')
    apifile.write_text(dumps({'a': 'b'}), 'utf-8')

    rf = tmpdir.join('rankfile.json')
    rf.write_text(dumps(None), 'utf-8')

    ff = fffake(
        apifile, nodelist=tmpdir.join('nodelist.json'),
        rankfile=rf, dry=True
    )
    assert _rankfile_load(ff) == (False, None)
    out, err = capsys.readouterr()
    assert 'ERROR' in out
    assert 'could' in out
    assert 'not' in out
    assert err == ''

    rf = tmpdir.join('rankfile.json')
    rf.write_text(dumps({'a': 'b'}), 'utf-8')

    ff = fffake(
        apifile, nodelist=tmpdir.join('nodelist.json'),
        rankfile=rf, dry=True
    )
    assert _rankfile_load(ff) == (False, None)
    out, err = capsys.readouterr()
    assert 'ERROR' in out
    assert 'is' in out
    assert 'no' in out
    assert err == ''

    assert tmpdir.remove() is None
Esempio n. 3
0
def test_rankfile_load_existing_file(tmpdir, fffake):
    apifile = tmpdir.join('api_file.json')
    apifile.write_text(dumps({'a': 'b'}), 'utf-8')
    rankfile = {'updated_at': 'now', 'nodes': [{'a': 'b'}, {'c': 'd'}]}
    rf = tmpdir.join('rankfile.json')
    rf.write_text(dumps(rankfile), 'utf-8')

    ff = fffake(apifile,
                nodelist=tmpdir.join('nodelist.json'),
                rankfile=rf,
                dry=True)
    assert _rankfile_load(ff) == (str(rf), rankfile)

    assert tmpdir.remove() is None
Esempio n. 4
0
def test_rankfile_load_existing_file(tmpdir, fffake):
    apifile = tmpdir.join('api_file.json')
    apifile.write_text(dumps({'a': 'b'}), 'utf-8')
    rankfile = {'updated_at': 'now', 'nodes': [{'a': 'b'}, {'c': 'd'}]}
    rf = tmpdir.join('rankfile.json')
    rf.write_text(dumps(rankfile), 'utf-8')

    ff = fffake(
        apifile, nodelist=tmpdir.join('nodelist.json'),
        rankfile=rf, dry=True
    )
    assert _rankfile_load(ff) == (str(rf), rankfile)

    assert tmpdir.remove() is None
Esempio n. 5
0
def test_rankfile_load_wrong_location(tmpdir, fffake):
    apifile = tmpdir.join('api_file.json')
    apifile.write_text(dumps({'a': 'b'}), 'utf-8')
    rf = tmpdir.mkdir('rankfolder')
    assert tmpdir.listdir() == [apifile, rf]
    assert rf.listdir() == []

    ff = fffake(
        apifile, nodelist=tmpdir.join('nodelist.json'), rankfile=rf, dry=True
    )
    assert ff.access_for('api') is True
    assert ff.access_for('nodelist') is True
    assert ff.access_for('rankfile') is True

    assert _rankfile_load(ff) == (False, None)

    assert tmpdir.remove() is None
Esempio n. 6
0
def test_rankfile_load_wrong_location(tmpdir, fffake):
    apifile = tmpdir.join('api_file.json')
    apifile.write_text(dumps({'a': 'b'}), 'utf-8')
    rf = tmpdir.mkdir('rankfolder')
    assert tmpdir.listdir() == [apifile, rf]
    assert rf.listdir() == []

    ff = fffake(apifile,
                nodelist=tmpdir.join('nodelist.json'),
                rankfile=rf,
                dry=True)
    assert ff.access_for('api') is True
    assert ff.access_for('nodelist') is True
    assert ff.access_for('rankfile') is True

    assert _rankfile_load(ff) == (False, None)

    assert tmpdir.remove() is None
Esempio n. 7
0
def test_rankfile_load_wrong_extension(tmpdir, fffake, capsys):
    apifile = tmpdir.join('api_file.json')
    apifile.write_text(dumps({'a': 'b'}), 'utf-8')

    ff = fffake(apifile,
                nodelist=tmpdir.join('nodelist.json'),
                rankfile=tmpdir.join('rankfile.txt'),
                dry=True)
    assert ff.access_for('api') is True
    assert ff.access_for('nodelist') is True
    assert ff.access_for('rankfile') is True

    assert _rankfile_load(ff) == (False, None)
    out, err = capsys.readouterr()
    assert 'ERROR' in out
    assert 'json' in out
    assert err == ''

    assert tmpdir.remove() is None
Esempio n. 8
0
def test_rankfile_load_wrong_extension(tmpdir, fffake, capsys):
    apifile = tmpdir.join('api_file.json')
    apifile.write_text(dumps({'a': 'b'}), 'utf-8')

    ff = fffake(
        apifile, nodelist=tmpdir.join('nodelist.json'),
        rankfile=tmpdir.join('rankfile.txt'), dry=True
    )
    assert ff.access_for('api') is True
    assert ff.access_for('nodelist') is True
    assert ff.access_for('rankfile') is True

    assert _rankfile_load(ff) == (False, None)
    out, err = capsys.readouterr()
    assert 'ERROR' in out
    assert 'json' in out
    assert err == ''

    assert tmpdir.remove() is None
Esempio n. 9
0
def test_rankfile_load_no_access(tmpdir, fffake):
    ff = fffake(tmpdir.join('api_file.json'), dry=True)

    assert _rankfile_load(ff) == (False, None)

    assert tmpdir.remove() is None
Esempio n. 10
0
def test_rankfile_load_no_access(tmpdir, fffake):
    ff = fffake(tmpdir.join('api_file.json'), dry=True)

    assert _rankfile_load(ff) == (False, None)

    assert tmpdir.remove() is None