Mocking with Rhino

Hey everyone,

Right know I am trying to mock some userinterface functions, so I can more easily test my plugins. However when I perform the test, the test succeeds and after that Rhino 7 crashes. Since the plugin is not build into IronPython, I am currently manually importing the package Mock (version 1.0.0. since it has no dependencies).

Does anyone have experience with this issue? Are you using a more compatible version of a mocking tool, if so which one? Or does Rhino not allow for the mocking of it is scriptsyntax tools?

With kind regards,

Hajo

The example of my code is as following:
"import sys
PATH = “~\Mock\mock-1.0.0\mock-1.0.0”
if PATH not in sys.path:
sys.path.append(PATH)

from mock import patch

from unittest import TestCase
import unittest
import rhinoscriptsyntax as rs

def get_input(text):
return input(test)

def answer():
ans = rs.GetString(“Give yes or no”)
if ans == “yes”:
return “You answered yes”
if ans == “no”:
return “You answered no”

class Test(TestCase):
@patch(‘rs.GetString’, return_value = “yes”)
def test_answer_yes(self, input):
self.asserEqual(answer(),“You answered yes”)

if name == ‘main’:
unittest.main()"

@eirannejad - is this something you can help with?

I’ve not tried unittest in RhinoPython, but from Grasshopper I found
I had to run unittest using something like:


 test_suite = unittest.TestLoader().discover(
                                               start_dir = start_dir
                                              ,pattern = '*test*.py'
                                              )

 result = unittest.TextTestRunner(o, verbosity=2).run(test_suite)
        

I’ve not played with Mocks either but I would not assume v1.0.0 from 2012 will play nicely out of the box with whichever version of unittest currently installed in Rhino that runs it. From my experience I’d be quite surprised if that were the case.