diff --git a/opbtest/opbtestmockable.py b/opbtest/opbtestmockable.py index 0f1ab14..1fffac4 100644 --- a/opbtest/opbtestmockable.py +++ b/opbtest/opbtestmockable.py @@ -3,6 +3,7 @@ class OpbTestMockable(): self.case = case self.filename = filename self.prepender = [] + self.replacers = {} self.inputs = {} self.proctotest = "" self.appender = ["\nopbtestquitfn: output sD, FF\n"] @@ -18,6 +19,13 @@ class OpbTestMockable(): self.prepender.append("load " + key + ", " + str(val) + "\n") return self + def replace(self, statement1, statement2): + self.replacers[statement1] = statement2 + return self + + def mockproc(self, procname): + return self.replace("call " + procname, "load s0, s0") + def mockinput(self, port, value): self.inputs[port] = value return self @@ -62,10 +70,24 @@ class OpbTestMockable(): newdata.append(line) return newdata + def setupreplaces(data): + newdata = [] + for line in data: + found = False + for key, value in self.replacers.items(): + if line.upper().replace(" ", "").startswith(key.upper().replace(" ", "")): + newdata.append(value) + found = True + if found is False: + newdata.append(line) + return newdata + if len(self.proctotest) > 0: data = setupproc(data) if len(self.inputs) > 0: data = setupinputs(data) + if len(self.replacers) > 0: + data = setupreplaces(data) firstjump = findlinebetween(data, "jump", "jump") diff --git a/test/mocks.psm4 b/test/mocks.psm4 new file mode 100644 index 0000000..f22ad5c --- /dev/null +++ b/test/mocks.psm4 @@ -0,0 +1,9 @@ +jump main + +proc myproc(s1 is bla) { + load s0, 11 +} + +main: + call myproc + output sD, FF \ No newline at end of file diff --git a/test/test_mocks.py b/test/test_mocks.py new file mode 100644 index 0000000..5582d29 --- /dev/null +++ b/test/test_mocks.py @@ -0,0 +1,16 @@ +from opbtest import OpbTestCase + + +class TestMocks(OpbTestCase): + + def test_mockproc_replaces_call_statements_with_dummies(self): + assert_that = self.load_file("mocks.psm4").mockproc("myproc").execute() + assert_that.reg("s0").contains(0) + + def test_replace_replaces_statement_with_given(self): + assert_that = self.load_file("mocks.psm4").replace("load s0, 11", "load s0, 3").execute() + assert_that.reg("s0").contains(3) + + def test_do_not_replace_anything(self): + assert_that = self.load_file("mocks.psm4").execute() + assert_that.reg("s0").contains(11)