Ejemplo n.º 1
0
def test_output_json(random1, random2):
    """Test to make sure the JSON is written out correctly"""
    data = [{
        'link': 'courage',
        'zelda': 'wisdom',
        'ganon': 'power',
        'num': 3
    }, {
        'random_one': random1,
        'random_two': random2
    }]
    output_file = WriteTester()
    script_output.write_json(output_file, data)
    lines = output_file.lines()
    assert len(lines) == 5
    assert json.loads(''.join(lines))
    assert lines[0] == '[\n'
    assert lines[2] == ',\n'
    assert lines[4] == '\n]\n'
    dict1 = json.loads(lines[1])
    dict2 = json.loads(lines[3])
    assert dict1['link'] == 'courage'
    assert dict1['zelda'] == 'wisdom'
    assert dict1['ganon'] == 'power'
    assert dict1['num'] == 3
    assert dict2['random_one'] == random1
    assert dict2['random_two'] == random2
Ejemplo n.º 2
0
def test_output_no_json():
    """Test writing empty JSON"""
    data = {}
    output_file = WriteTester()
    script_output.write_json(output_file, data)
    lines = output_file.lines()
    assert len(lines) == 2
    assert lines[0] == '[\n'
    assert lines[1] == '\n]\n'
Ejemplo n.º 3
0
def test_output_no_json():
    """Test writing empty JSON"""
    data = {}
    output_file = WriteTester()
    script_output.write_json(output_file, data)
    lines = output_file.lines()
    assert len(lines) == 2
    assert lines[0] == '[\n'
    assert lines[1] == '\n]\n'
Ejemplo n.º 4
0
def test_output_json(random1, random2):
    """Test to make sure the JSON is written out correctly"""
    data = [{'link': 'courage', 'zelda': 'wisdom', 'ganon': 'power', 'num': 3},
            {'random_one': random1, 'random_two': random2}]
    output_file = WriteTester()
    script_output.write_json(output_file, data)
    lines = output_file.lines()
    assert len(lines) == 5
    assert json.loads(''.join(lines))
    assert lines[0] == '[\n'
    assert lines[2] == ',\n'
    assert lines[4] == '\n]\n'
    dict1 = json.loads(lines[1])
    dict2 = json.loads(lines[3])
    assert dict1['link'] == 'courage'
    assert dict1['zelda'] == 'wisdom'
    assert dict1['ganon'] == 'power'
    assert dict1['num'] == 3
    assert dict2['random_one'] == random1
    assert dict2['random_two'] == random2