pyinvoke / invoke

Pythonic task management & command execution.
http://pyinvoke.org
BSD 2-Clause "Simplified" License
4.31k stars 365 forks source link

Regex support for MockContext is broken? #952

Closed red8888 closed 11 months ago

red8888 commented 1 year ago

This works:

# Task
@task
def derp(ctx: Context):
    cmd_one = ctx.run("ls -a", warn=True, hide=False, echo=True)
    cmd_two = ctx.run("ls -l", warn=True, hide=False, echo=True)
    print(cmd_one)
    print(cmd_two)

# Unit test
@pytest.mark.unittest
def test__derp():
    ctx = MockContext(
        run={
            "ls -a": Result("aaaaa"),
            "ls -l": Result("bbbbb"),
        }
    )

But this does not

# Unit test
@pytest.mark.unittest
def test__derp():
    cmd_one = re.compile(r".*")
    cmd_two = re.compile(r".*")

    ctx = MockContext(
        run={
            cmd_one: Result("aaaaa"),
            cmd_two: Result("bbbbb"),
        }
    )

I get a not implemented error. .* should catch everything. Initially I tried .*a and .*l and then found nothing seems to work.