<reponame>sahansk2/git-gud
import os
from gitgud.level_builder import LevelBase
from gitgud.structures import Skill
from pathlib import Path
from functools import partial
import subprocess
import pytest


def level_name_id(obj):
    if isinstance(obj, LevelBase):
        return f"Level({obj.skill.name}/{obj.name})"
    elif isinstance(obj, Skill):
        return f"Skill({obj.name})"
    return None

pytest_mark_parametrize_ids = partial(pytest.mark.parametrize, ids=level_name_id)


def write_file(filepath):
    with open(Path(filepath), "w") as newfile:
        newfile.write("{} content".format(filepath))

def simulate(gg, level, commands):
    level.setup()

    for command in commands:
        command = command.strip()
        if len(command) == 0 or command[0] == '#':
            continue
        # Only test if there are commands which change state.
        # if run_pretest:
        #     assert not level._test()
        # TODO: Find a reasonable alternative

        print(f'Calling command: {command}')
        if command.startswith('{create}'):
            filename = command[len('{create} '):].strip()
            write_file(filename)
        elif '^' in command and os.name == 'nt':
            command = command.replace('^', '^^')
        subprocess.call(command, shell=True)

    assert level.test()

import os
from gitgud.level_builder import LevelBase
from gitgud.structures import Skill
from pathlib import Path
from functools import partial
import subprocess
import pytest


def level_name_id(obj):
    if isinstance(obj, LevelBase):
        return f"Level({obj.skill.name}/{obj.name})"
    elif isinstance(obj, Skill):
        return f"Skill({obj.name})"
    return None

pytest_mark_parametrize_ids = partial(pytest.mark.parametrize, ids=level_name_id)


def write_file(filepath):
    with open(Path(filepath), "w") as newfile:
        newfile.write("{} content".format(filepath))

def simulate(gg, level, commands):
    level.setup()

    for command in commands:
        command = command.strip()
        if len(command) == 0 or command[0] == '#':
            continue
        # Only test if there are commands which change state.
        # if run_pretest:
        #     assert not level._test()
        # TODO: Find a reasonable alternative

        print(f'Calling command: {command}')
        if command.startswith('{create}'):
            filename = command[len('{create} '):].strip()
            write_file(filename)
        elif '^' in command and os.name == 'nt':
            command = command.replace('^', '^^')
        subprocess.call(command, shell=True)

    assert level.test()
# Only test if there are commands which change state. # if run_pretest: #     assert not level._test() # TODO: Find a reasonable alternative