<commit_before>import gdb
import pytest

import tests
from pwndbg.commands import command_names
from pwndbg.commands.shell import shellcmd_names

BINARY = tests.binaries.get("heap_bins.out")

# TODO: See if we can reduce the number of commands we need to skip
blacklisted_commands = set(["disasm", "unhex", "bugreport", "try_free", "errno", "nextproginstr"])

# Don't run any shell commands
blacklisted_commands.update(shellcmd_names)

# TODO: Figure out why these are being thrown and then remove this
whitelisted_exceptions = [
    "Cannot access memory at address",
    "Cannot insert breakpoint",
    "Warning:",
    "The program is not being run",
]


@pytest.mark.skip(reason="flaky test")
def test_commands(start_binary):
    for name in command_names:
        print("Running command", name)
        try:
            start_binary(BINARY)

            if name in blacklisted_commands:
                continue

            gdb.execute(name)
        except gdb.error as e:
            ignore = False
            for ex in whitelisted_exceptions:
                if ex in str(e):
                    ignore = True
                    print("Ignoring exception in command", name)
                    break

            if not ignore:
                raise e<commit_msg>Improved test_commands.py (#1350)<commit_after>import os

import gdb
import pytest

import tests
from pwndbg.commands import command_names
from pwndbg.commands.shell import shellcmd_names

BINARY = tests.binaries.get("heap_bins.out")

# TODO: See if we can reduce the number of commands we need to skip
disallowed_commands = set(
    [
        # requires user input
        "ipi",
        # takes too long
        "nextproginstr",
    ]
)

# Don't run any shell commands
disallowed_commands.update(shellcmd_names)

filtered_commands = command_names - disallowed_commands

# TODO: Figure out why these are being thrown and then remove this
allowed_exceptions = [
    "Cannot access memory at address",
    "Cannot insert breakpoint",
    "Warning:",
    "The program is not being run",
]


running_on_ci = os.getenv("GITHUB_ACTIONS")
run_flaky = os.getenv("RUN_FLAKY")

should_skip_test = not running_on_ci and not run_flaky
if should_skip_test:
    # The test name will look like "test_commands[*]" if the test is skipped
    filtered_commands = set("*")


@pytest.mark.parametrize("name", filtered_commands)
@pytest.mark.skipif(condition=should_skip_test, reason="flaky test")
@pytest.mark.xfail(reason="flaky test")
def test_commands(start_binary, name):
    print("Running command", name)
    try:
        start_binary(BINARY)
        gdb.execute(name)
    except gdb.error as e:
        ignore = False
        for ex in allowed_exceptions:
            if ex in str(e):
                ignore = True
                print("Ignoring exception in command", name)
                break

        if not ignore:
            raise e
{'fraction_non_alphanumeric': 0.08204067562909341, 'fraction_numerical': 0.0013788348845225785, 'mean_word_length': 2.803407601572739, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4539983', 'n_tokens_mistral': 863, 'n_tokens_neox': 835, 'n_words': 270}