示例#1
0
def test_box_metadata_file_read_write(vagrant_box_metadata):
    file_name, expected = vagrant_box_metadata
    input_file_url = 'file://{}'.format(file_name)
    if expected:
        input_metadata = BoxMetadata(input_file_url)
        assert input_metadata.name
        assert isinstance(input_metadata.versions, list)

        file_path = os.path.dirname(file_name)
        output_file_name = os.path.join(file_path, 'output.json')
        input_metadata.write(output_file_name)

        with open(file_name, 'r') as input_file_object:
            input_data = json.load(input_file_object)

        with open(output_file_name, 'r') as output_file_object:
            output_data = json.load(output_file_object)

        assert input_data == output_data

    else:
        with pytest.raises(BoxMetadataException):
            BoxMetadata(input_file_url)
示例#2
0
def test_box_metadata_file_write_error():
    metadata = BoxMetadata(name = 'test')
    with pytest.raises(BoxMetadataException):
        metadata.write('/path/does/not/exist/metadata.json')