Skip to content

Resolve class methods from context-local variables #1

@grandrew

Description

@grandrew

In this situation:

import pytest, gc
import ordered, random

__author__ = "Andrew Gree"
__copyright__ = "CriticalHop Inc."
__license__ = "MIT"


class MyVars:
    x: int
    steps: int
    def __init__(self) -> None:
        self.x = 0
        self.steps = 0

    def plus_x(self):
        self.x += 3
        self.count_steps()

    def minus_x(self):
        self.x -= 2
        self.count_steps()
    
    def count_steps(self):
        self.steps += 1

@pytest.mark.skip(reason="TODO")
def test_partial_context_oo_full():
    m = MyVars()
    m.x = 5
    with ordered.orderedcontext():
        # exit ordered context without exceptions with minimum steps
        while m.x != 12:  
            ordered.choice()()  
    assert m.x == 12
    assert m.steps == 4

we're calling choice() with no parameters. This code fails as no methods for m are generated.

A solution needed to have a logically expected behaviour:

  1. all variables explicitly used in the context are scanned for their class' methods
  2. if choice() is selecting all functions from heap then it's huge as Python always has a lot of stuff loaded. Maybe choice() must actually scan this module's globals() for functions and methods?

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingquestionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions