<commit_before>import pytest
import subprocess
import os
import sys

prefix = '.'
for i in range(0,3):
    if os.path.exists(os.path.join(prefix, 'pyfat.py')):
        sys.path.insert(0, prefix)
        break
    else:
        prefix = '../' + prefix

import pyfat

from common import *

def do_a_test(tmpdir, outfile, check_func):
    testout = tmpdir.join("writetest.img")

    # Now open up the floppy with pyfat and check some things out.
    fat = pyfat.PyFat()
    fat.open(outfile)
    check_func(fat, tmpdir, os.stat(outfile).st_size)
    fat.write(str(testout))
    fat.close()

    # Now round-trip through write.
    fat2 = pyfat.PyFat()
    fat2.open(str(testout))
    check_func(fat2, tmpdir, os.stat(str(testout)).st_size)
    fat2.close()

def test_parse_nofiles(tmpdir):
    indir = tmpdir.mkdir("nofiles")
    outfile = str(indir) + ".img"
    subprocess.call(["mkfs.msdos", "-C", str(outfile), "1440"])

    do_a_test(tmpdir, outfile, check_nofiles)

def test_parse_onefile(tmpdir):
    indir = tmpdir.mkdir("onefile")
    outfile = str(indir) + ".img"
    subprocess.call(["mkfs.msdos", "-C", str(outfile), "1440"])
    foofile = os.path.join(str(indir), "foo")
    with open(foofile, "wb") as outfp:
        outfp.write("foo\n")
    subprocess.call(["mcopy", "-n", "-o", "-i", str(outfile), foofile, "::FOO"])

    do_a_test(tmpdir, outfile, check_onefile)

def test_parse_onedir(tmpdir):
    indir = tmpdir.mkdir("onedir")
    outfile = str(indir) + ".img"
    subprocess.call(["mkfs.msdos", "-C", str(outfile), "1440"])
    subprocess.call(["mmd", "-i", str(outfile), "DIR1"])

    do_a_test(tmpdir, outfile, check_onedir)

def test_parse_onefile_system(tmpdir):
    indir = tmpdir.mkdir("onefilesystem")
    outfile = str(indir) + ".img"
    subprocess.call(["mkfs.msdos", "-C", str(outfile), "1440"])
    foofile = os.path.join(str(indir), "foo")
    with open(foofile, "wb") as outfp:
        outfp.write("foo\n")
    subprocess.call(["mcopy", "-n", "-o", "-i", str(outfile), foofile, "::FOO"])
    subprocess.call(["mattrib", "+s", "-i", str(outfile), "::FOO"])

    do_a_test(tmpdir, outfile, check_onefile_system)

def test_parse_onefile_archive(tmpdir):
    indir = tmpdir.mkdir("onefilearchive")
    outfile = str(indir) + ".img"
    subprocess.call(["mkfs.msdos", "-C", str(outfile), "1440"])
    foofile = os.path.join(str(indir), "foo")
    with open(foofile, "wb") as outfp:
        outfp.write("foo\n")
    subprocess.call(["mcopy", "-n", "-o", "-i", str(outfile), foofile, "::FOO"])
    subprocess.call(["mattrib", "+a", "-i", str(outfile), "::FOO"])

    do_a_test(tmpdir, outfile, check_onefile_archive)

def test_parse_onefile_hidden(tmpdir):
    indir = tmpdir.mkdir("onefilehidden")
    outfile = str(indir) + ".img"
    subprocess.call(["mkfs.msdos", "-C", str(outfile), "1440"])
    foofile = os.path.join(str(indir), "foo")
    with open(foofile, "wb") as outfp:
        outfp.write("foo\n")
    subprocess.call(["mcopy", "-n", "-o", "-i", str(outfile), foofile, "::FOO"])
    subprocess.call(["mattrib", "+h", "-i", str(outfile), "::FOO"])

    do_a_test(tmpdir, outfile, check_onefile_hidden)

def test_parse_onefile_read_only(tmpdir):
    indir = tmpdir.mkdir("onefileread_only")
    outfile = str(indir) + ".img"
    subprocess.call(["mkfs.msdos", "-C", str(outfile), "1440"])
    foofile = os.path.join(str(indir), "foo")
    with open(foofile, "wb") as outfp:
        outfp.write("foo\n")
    subprocess.call(["mcopy", "-n", "-o", "-i", str(outfile), foofile, "::FOO"])
    subprocess.call(["mattrib", "+r", "-i", str(outfile), "::FOO"])

    do_a_test(tmpdir, outfile, check_onefile_read_only)

def test_parse_onefile_all_attr(tmpdir):
    indir = tmpdir.mkdir("onefileallattr")
    outfile = str(indir) + ".img"
    subprocess.call(["mkfs.msdos", "-C", str(outfile), "1440"])
    foofile = os.path.join(str(indir), "foo")
    with open(foofile, "wb") as outfp:
        outfp.write("foo\n")
    subprocess.call(["mcopy", "-n", "-o", "-i", str(outfile), foofile, "::FOO"])
    subprocess.call(["mattrib", "+r", "-i", str(outfile), "::FOO"])
    subprocess.call(["mattrib", "+h", "-i", str(outfile), "::FOO"])
    subprocess.call(["mattrib", "+s", "-i", str(outfile), "::FOO"])
    subprocess.call(["mattrib", "+a", "-i", str(outfile), "::FOO"])

    do_a_test(tmpdir, outfile, check_onefile_all_attr)

def test_parse_onefile_no_attr(tmpdir):
    indir = tmpdir.mkdir("onefilenoattr")
    outfile = str(indir) + ".img"
    subprocess.call(["mkfs.msdos", "-C", str(outfile), "1440"])
    with open(os.path.join(str(indir), "foo"), "wb") as outfp:
        outfp.write("foo\n")
    subprocess.call(["mcopy", "-n", "-o", "-i", str(outfile), "foo", "::FOO"])
    subprocess.call(["mattrib", "-r", "-i", str(outfile), "::FOO"])
    subprocess.call(["mattrib", "-h", "-i", str(outfile), "::FOO"])
    subprocess.call(["mattrib", "-s", "-i", str(outfile), "::FOO"])
    subprocess.call(["mattrib", "-a", "-i", str(outfile), "::FOO"])

    do_a_test(tmpdir, outfile, check_onefile_no_attr)<commit_msg>Fix one more instance.<commit_after>import pytest
import subprocess
import os
import sys

prefix = '.'
for i in range(0,3):
    if os.path.exists(os.path.join(prefix, 'pyfat.py')):
        sys.path.insert(0, prefix)
        break
    else:
        prefix = '../' + prefix

import pyfat

from common import *

def do_a_test(tmpdir, outfile, check_func):
    testout = tmpdir.join("writetest.img")

    # Now open up the floppy with pyfat and check some things out.
    fat = pyfat.PyFat()
    fat.open(outfile)
    check_func(fat, tmpdir, os.stat(outfile).st_size)
    fat.write(str(testout))
    fat.close()

    # Now round-trip through write.
    fat2 = pyfat.PyFat()
    fat2.open(str(testout))
    check_func(fat2, tmpdir, os.stat(str(testout)).st_size)
    fat2.close()

def test_parse_nofiles(tmpdir):
    indir = tmpdir.mkdir("nofiles")
    outfile = str(indir) + ".img"
    subprocess.call(["mkfs.msdos", "-C", str(outfile), "1440"])

    do_a_test(tmpdir, outfile, check_nofiles)

def test_parse_onefile(tmpdir):
    indir = tmpdir.mkdir("onefile")
    outfile = str(indir) + ".img"
    subprocess.call(["mkfs.msdos", "-C", str(outfile), "1440"])
    foofile = os.path.join(str(indir), "foo")
    with open(foofile, "wb") as outfp:
        outfp.write("foo\n")
    subprocess.call(["mcopy", "-n", "-o", "-i", str(outfile), foofile, "::FOO"])

    do_a_test(tmpdir, outfile, check_onefile)

def test_parse_onedir(tmpdir):
    indir = tmpdir.mkdir("onedir")
    outfile = str(indir) + ".img"
    subprocess.call(["mkfs.msdos", "-C", str(outfile), "1440"])
    subprocess.call(["mmd", "-i", str(outfile), "DIR1"])

    do_a_test(tmpdir, outfile, check_onedir)

def test_parse_onefile_system(tmpdir):
    indir = tmpdir.mkdir("onefilesystem")
    outfile = str(indir) + ".img"
    subprocess.call(["mkfs.msdos", "-C", str(outfile), "1440"])
    foofile = os.path.join(str(indir), "foo")
    with open(foofile, "wb") as outfp:
        outfp.write("foo\n")
    subprocess.call(["mcopy", "-n", "-o", "-i", str(outfile), foofile, "::FOO"])
    subprocess.call(["mattrib", "+s", "-i", str(outfile), "::FOO"])

    do_a_test(tmpdir, outfile, check_onefile_system)

def test_parse_onefile_archive(tmpdir):
    indir = tmpdir.mkdir("onefilearchive")
    outfile = str(indir) + ".img"
    subprocess.call(["mkfs.msdos", "-C", str(outfile), "1440"])
    foofile = os.path.join(str(indir), "foo")
    with open(foofile, "wb") as outfp:
        outfp.write("foo\n")
    subprocess.call(["mcopy", "-n", "-o", "-i", str(outfile), foofile, "::FOO"])
    subprocess.call(["mattrib", "+a", "-i", str(outfile), "::FOO"])

    do_a_test(tmpdir, outfile, check_onefile_archive)

def test_parse_onefile_hidden(tmpdir):
    indir = tmpdir.mkdir("onefilehidden")
    outfile = str(indir) + ".img"
    subprocess.call(["mkfs.msdos", "-C", str(outfile), "1440"])
    foofile = os.path.join(str(indir), "foo")
    with open(foofile, "wb") as outfp:
        outfp.write("foo\n")
    subprocess.call(["mcopy", "-n", "-o", "-i", str(outfile), foofile, "::FOO"])
    subprocess.call(["mattrib", "+h", "-i", str(outfile), "::FOO"])

    do_a_test(tmpdir, outfile, check_onefile_hidden)

def test_parse_onefile_read_only(tmpdir):
    indir = tmpdir.mkdir("onefileread_only")
    outfile = str(indir) + ".img"
    subprocess.call(["mkfs.msdos", "-C", str(outfile), "1440"])
    foofile = os.path.join(str(indir), "foo")
    with open(foofile, "wb") as outfp:
        outfp.write("foo\n")
    subprocess.call(["mcopy", "-n", "-o", "-i", str(outfile), foofile, "::FOO"])
    subprocess.call(["mattrib", "+r", "-i", str(outfile), "::FOO"])

    do_a_test(tmpdir, outfile, check_onefile_read_only)

def test_parse_onefile_all_attr(tmpdir):
    indir = tmpdir.mkdir("onefileallattr")
    outfile = str(indir) + ".img"
    subprocess.call(["mkfs.msdos", "-C", str(outfile), "1440"])
    foofile = os.path.join(str(indir), "foo")
    with open(foofile, "wb") as outfp:
        outfp.write("foo\n")
    subprocess.call(["mcopy", "-n", "-o", "-i", str(outfile), foofile, "::FOO"])
    subprocess.call(["mattrib", "+r", "-i", str(outfile), "::FOO"])
    subprocess.call(["mattrib", "+h", "-i", str(outfile), "::FOO"])
    subprocess.call(["mattrib", "+s", "-i", str(outfile), "::FOO"])
    subprocess.call(["mattrib", "+a", "-i", str(outfile), "::FOO"])

    do_a_test(tmpdir, outfile, check_onefile_all_attr)

def test_parse_onefile_no_attr(tmpdir):
    indir = tmpdir.mkdir("onefilenoattr")
    outfile = str(indir) + ".img"
    subprocess.call(["mkfs.msdos", "-C", str(outfile), "1440"])
    foofile = os.path.join(str(indir), "foo")
    with open(foofile, "wb") as outfp:
        outfp.write("foo\n")
    subprocess.call(["mcopy", "-n", "-o", "-i", str(outfile), foofile, "::FOO"])
    subprocess.call(["mattrib", "-r", "-i", str(outfile), "::FOO"])
    subprocess.call(["mattrib", "-h", "-i", str(outfile), "::FOO"])
    subprocess.call(["mattrib", "-s", "-i", str(outfile), "::FOO"])
    subprocess.call(["mattrib", "-a", "-i", str(outfile), "::FOO"])

    do_a_test(tmpdir, outfile, check_onefile_no_attr)
{'fraction_non_alphanumeric': 0.21473059812160158, 'fraction_numerical': 0.00869995056846268, 'mean_word_length': 4.022840119165839, 'pattern_counts': {'":': 38, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3785046', 'n_tokens_mistral': 4137, 'n_tokens_neox': 4025, 'n_words': 732}