<commit_before>using Images

urlbase = "http://www.imagemagick.org/Usage/images/"

const savedir = joinpath(tempdir(), "Images")
const writedir = joinpath(savedir, "write")

function getfile(name)
    file = joinpath(savedir, name)
    if !isfile(file)
        file = download(urlbase*name, file)
    end
    file
end

if !isdir(savedir)
    mkdir(savedir)
end
if !isdir(writedir)
    mkdir(writedir)
end

# Gray
file = getfile("pencil_tile.gif")
img = imread(file)
@assert colorspace(img) == "Gray"
@assert ndims(img) == 2
@assert colordim(img) == 0
@assert eltype(img) == Uint8
outname = joinpath(writedir, "pencil_tile.tif")
imwrite(img, outname)
imgc = imread(outname)
@assert img.data == imgc.data


# Gray with alpha channel
file = getfile("gamma_rules.png")
img = imread(file)
@assert colorspace(img) == "GrayAlpha"
@assert ndims(img) == 3
@assert colordim(img) == 3
@assert eltype(img) == Uint8
# outname = joinpath(writedir, "gamma_rules.png")
# imwrite(img, outname)
# imgc = imread(outname)
# @assert img.data == imgc.data

# RGB
file = getfile("rose.png")
img = imread(file)
@assert colorspace(img) == "RGB"
@assert ndims(img) == 3
@assert colordim(img) == 1
@assert size(img, 1) == 3
@assert eltype(img) == Uint8
outname = joinpath(writedir, "rose.ppm")
imwrite(img, outname)
imgc = imread(outname)
@assert img.data == imgc.data

# RGBA with 16 bit depth
file = getfile("autumn_leaves.png")
img = imread(file)
@assert colorspace(img) == "RGBA"
@assert ndims(img) == 3
@assert colordim(img) == 1
@assert size(img, 1) == 4
@assert eltype(img) == Uint16
# outname = joinpath(writedir, "autumn_leaves.png")
# imwrite(img, outname)
# imgc = imread(outname)
# @assert img.data == imgc.data

# Indexed
file = getfile("present.gif")
img = imread(file)
<commit_msg>Add a sleep() to allow writing to finish before testing via read<commit_after>using Images

urlbase = "http://www.imagemagick.org/Usage/images/"

const savedir = joinpath(tempdir(), "Images")
const writedir = joinpath(savedir, "write")

function getfile(name)
    file = joinpath(savedir, name)
    if !isfile(file)
        file = download(urlbase*name, file)
    end
    file
end

if !isdir(savedir)
    mkdir(savedir)
end
if !isdir(writedir)
    mkdir(writedir)
end

# Gray
file = getfile("pencil_tile.gif")
img = imread(file)
@assert colorspace(img) == "Gray"
@assert ndims(img) == 2
@assert colordim(img) == 0
@assert eltype(img) == Uint8
outname = joinpath(writedir, "pencil_tile.tif")
imwrite(img, outname)
sleep(0.2)
imgc = imread(outname)
@assert img.data == imgc.data


# Gray with alpha channel
file = getfile("gamma_rules.png")
img = imread(file)
@assert colorspace(img) == "GrayAlpha"
@assert ndims(img) == 3
@assert colordim(img) == 3
@assert eltype(img) == Uint8
# outname = joinpath(writedir, "gamma_rules.png")
# imwrite(img, outname)
# imgc = imread(outname)
# @assert img.data == imgc.data

# RGB
file = getfile("rose.png")
img = imread(file)
@assert colorspace(img) == "RGB"
@assert ndims(img) == 3
@assert colordim(img) == 1
@assert size(img, 1) == 3
@assert eltype(img) == Uint8
outname = joinpath(writedir, "rose.ppm")
imwrite(img, outname)
imgc = imread(outname)
@assert img.data == imgc.data

# RGBA with 16 bit depth
file = getfile("autumn_leaves.png")
img = imread(file)
@assert colorspace(img) == "RGBA"
@assert ndims(img) == 3
@assert colordim(img) == 1
@assert size(img, 1) == 4
@assert eltype(img) == Uint16
# outname = joinpath(writedir, "autumn_leaves.png")
# imwrite(img, outname)
# imgc = imread(outname)
# @assert img.data == imgc.data

# Indexed
file = getfile("present.gif")
img = imread(file)

{'fraction_non_alphanumeric': 0.15805555555555556, 'fraction_numerical': 0.011111111111111112, 'mean_word_length': 5.166095890410959, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6916045', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1395, 'n_words': 334}