<commit_before>from contextlib import contextmanager
import subprocess
import yaml
import sys

from reprounzip.unpackers.common import join_root
from rpaths import Path


@contextmanager
def in_temp_dir():
    tmp = Path.tempdir(prefix='reprozip_tests_')
    try:
        with tmp.in_dir():
            yield
    finally:
        tmp.rmtree(ignore_errors=True)


tests = Path(__file__).parent.absolute()


def build(target, *sources):
    subprocess.check_call(['cc', '-o', target] + [(tests / s).path
                                                  for s in sources])


if len(sys.argv) == 2 and sys.argv[1] == '--interactive':
    interactive = True
elif len(sys.argv) == 1:
    interactive = False
else:
    print("Usage: run.py [--interactive]")
    sys.exit(1)


with in_temp_dir():
    # Build
    build('simple', 'simple.c')
    # Trace
    subprocess.check_call(['reprozip', '-v', '-v', 'trace',
                           '-d', 'rpz-simple',
                           './simple',
                           (tests / 'simple_input.txt').path,
                           'simple_output.txt'])
    orig_output_location = Path('simple_output.txt').absolute()
    assert orig_output_location.is_file()
    with orig_output_location.open(encoding='utf-8') as fp:
        assert fp.read().strip() == '42'
    orig_output_location.remove()
    # Read config
    with Path('rpz-simple/config.yml').open(encoding='utf-8') as fp:
        conf = yaml.safe_load(fp)
    other_files = set(Path(f).absolute() for f in conf['other_files'])
    expected = [Path('simple'), (tests / 'simple_input.txt')]
    assert other_files.issuperset([f.absolute() for f in expected])
    # Pack
    subprocess.check_call(['reprozip', '-v', '-v', 'pack',
                           '-d', 'rpz-simple',
                           'simple.rpz'])
    # Unpack directory
    subprocess.check_call(['reprounzip', '-v', '-v', 'directory',
                           'simple.rpz', 'simpledir'])
    # Run script<commit_msg>Fixes issue in run.py with my test setup<commit_after>from contextlib import contextmanager
import subprocess
import yaml
import sys

from reprounzip.unpackers.common import join_root
from rpaths import Path


@contextmanager
def in_temp_dir():
    tmp = Path.tempdir(prefix='reprozip_tests_')
    try:
        with tmp.in_dir():
            yield
    finally:
        tmp.rmtree(ignore_errors=True)


tests = Path(__file__).parent.absolute()


def build(target, *sources):
    subprocess.check_call(['cc', '-o', target] + [(tests / s).path
                                                  for s in sources])


if len(sys.argv) == 2 and sys.argv[1] == '--interactive':
    interactive = True
elif len(sys.argv) == 1:
    interactive = False
else:
    print("Usage: run.py [--interactive]")
    sys.exit(1)


with in_temp_dir():
    # Build
    build('simple', 'simple.c')
    # Trace
    subprocess.check_call(['reprozip', '-v', '-v', 'trace',
                           '-d', 'rpz-simple',
                           './simple',
                           (tests / 'simple_input.txt').path,
                           'simple_output.txt'])
    orig_output_location = Path('simple_output.txt').absolute()
    assert orig_output_location.is_file()
    with orig_output_location.open(encoding='utf-8') as fp:
        assert fp.read().strip() == '42'
    orig_output_location.remove()
    # Read config
    with Path('rpz-simple/config.yml').open(encoding='utf-8') as fp:
        conf = yaml.safe_load(fp)
    other_files = set(Path(f).absolute() for f in conf['other_files'])
    expected = [Path('simple'), (tests / 'simple_input.txt')]
    assert other_files.issuperset([f.resolve() for f in expected])
    # Pack
    subprocess.check_call(['reprozip', '-v', '-v', 'pack',
                           '-d', 'rpz-simple',
                           'simple.rpz'])
    # Unpack directory
    subprocess.check_call(['reprounzip', '-v', '-v', 'directory',
                           'simple.rpz', 'simpledir'])
    # Run script
{'fraction_non_alphanumeric': 0.14701492537313432, 'fraction_numerical': 0.003980099502487562, 'mean_word_length': 2.2664500406173844, 'pattern_counts': {'":': 0, '<': 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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5234292', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1220, 'n_words': 268}