diff options
author | Tim Harder <radhermit@gmail.com> | 2021-03-04 13:32:55 -0700 |
---|---|---|
committer | Tim Harder <radhermit@gmail.com> | 2021-03-04 13:44:12 -0700 |
commit | 69eb509bf9dad811fa7060807c2be4d0570bc7cc (patch) | |
tree | 2a33eda132f5300ee3d20bbc5a3e12bb69abd6df /tests/test_dependant_methods.py | |
parent | various tox and github testing updates (diff) | |
download | snakeoil-69eb509bf9dad811fa7060807c2be4d0570bc7cc.tar.gz snakeoil-69eb509bf9dad811fa7060807c2be4d0570bc7cc.tar.bz2 snakeoil-69eb509bf9dad811fa7060807c2be4d0570bc7cc.zip |
tests: move to main repo root dir
Diffstat (limited to 'tests/test_dependant_methods.py')
-rw-r--r-- | tests/test_dependant_methods.py | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/test_dependant_methods.py b/tests/test_dependant_methods.py new file mode 100644 index 00000000..ffd6d363 --- /dev/null +++ b/tests/test_dependant_methods.py @@ -0,0 +1,84 @@ +from snakeoil import currying +from snakeoil import dependant_methods as dm + + +def func(self, seq, data, val=True): + seq.append(data) + return val + + +class TestDependantMethods: + + @staticmethod + def generate_instance(methods, dependencies): + class Class(metaclass=dm.ForcedDepends): + stage_depends = dict(dependencies) + + locals().update(list(methods.items())) + + return Class() + + def test_no_dependant_methods(self): + assert self.generate_instance({}, {}) + + def test_return_checking(self): + results = [] + o = self.generate_instance( + {str(x): currying.post_curry(func, results, x) for x in range(10)}, + {str(x): str(x - 1) for x in range(1, 10)}) + getattr(o, "9")() + assert results == list(range(10)) + results = [] + o = self.generate_instance( + {str(x): currying.post_curry(func, results, x, False) for x in range(10)}, + {str(x): str(x - 1) for x in range(1, 10)}) + getattr(o, "9")() + assert results == [0] + getattr(o, "9")() + assert results == [0, 0] + + def test_stage_awareness(self): + results = [] + o = self.generate_instance( + {str(x): currying.post_curry(func, results, x) for x in range(10)}, + {str(x): str(x - 1) for x in range(1, 10)}) + getattr(o, "1")() + assert results == [0, 1] + getattr(o, "2")() + assert results == [0, 1, 2] + getattr(o, "2")() + assert results == [0, 1, 2] + o.__set_stage_state__(["0", "1"]) + l = [] + o.__stage_step_callback__ = l.append + getattr(o, "2")() + assert results == [0, 1, 2, 2] + assert l == ["2"] + + def test_stage_depends(self): + results = [] + methods = {str(x): currying.post_curry(func, results, x) for x in range(10)} + deps = {str(x): str(x - 1) for x in range(1, 10)} + deps["1"] = ["0", "a"] + methods["a"] = currying.post_curry(func, results, "a") + o = self.generate_instance(methods, deps) + getattr(o, "1")() + assert results == [0, "a", 1] + getattr(o, "2")() + assert results == [0, "a", 1, 2] + + def test_ignore_deps(self): + results = [] + o = self.generate_instance( + {str(x): currying.post_curry(func, results, x) for x in range(10)}, + {str(x): str(x - 1) for x in range(1, 10)}) + getattr(o, '2')(ignore_deps=True) + assert [2] == results + + def test_no_deps(self): + results = [] + o = self.generate_instance( + {str(x): currying.post_curry(func, results, x) for x in range(10)}, + {}) + getattr(o, '2')() + assert [2] == results |