/srv/irclogs.ubuntu.com/2014/05/09/#ubuntu-autopilot.txt

elopiothomi, veebers: I have a customproxyobject that has a slow_drag method in it. I want to test the number of times that drag method was called.00:00
elopioI can't use mock to count the number of time drag was called, because that would do nothing instead of dragging.00:02
elopioand I can't make a test class that inherits from my customproxyobject class and counts the number of times drag was called, because I won't be able to use it on select_single00:02
elopioI'm out of ideas, but I might be missing some simple and straight-forward way to do it.00:04
elopiothomi, veebers: how would you do it?00:04
veeberselopio: hmm, I'm just checking a couple of ideas out. My first suggestion was super gross so I didn't even type it out :-)00:05
thomielopio: a decorator?00:05
veebersI'm sure you acn do it thought, just pondering it00:05
thomielopio: make a decorator that counts calls00:05
veebersthomi: aye, that's what I was thinking, wrap the call and have it count00:05
elopiothomi, veebers: but then it will count always. Not just for my test.00:06
thomielopio: hmmm00:06
veeberscould you have something like: with MethodCaller(object) as smoething:\n\n print something['method_'name'] => 1200:07
thomiveebers: but that only works if he controls the call site00:08
thomielopio: make your custom proxy class count the calls only when it's been enabled with a context manager00:08
thomiso you'd do:00:08
elopioI didn't get that.00:08
thomiwith my_custom_proxy_class_instance.count_calls():00:08
thomi    # test code00:08
thomiassert my_custom_proxy_class_instance.call_count == 1200:08
elopioI mean, the methodcaller solution.00:08
elopiothomi: ok, I don't like that, but I guess I'll go with it.00:10
thomielopio: it's quite an unusual requirement00:10
elopiomy ideal solution was something like mock.patch(CustomProxyObj, 'slow_drag'), so I didn't have to touch the original class00:11
elopiobut instead of patching it with a mock, it keeps the same slow_drag implementation but records the call_count.00:12
thomielopio: why do you want this? There's probably a better way00:12
thomicounting the number of calls seems like you're testing the wrong thing TBH00:12
elopioI'll propose it to mfoord, charge a cent for everybody who uses it, and then I will earn one cent.00:12
elopiothomi: on the qquicklistviews we have to drag the list many times in order to find items, right?00:13
elopioI'm now working with circular lists00:13
elopioif we drag too fast, we skip some items00:13
elopiobut as it's circular, we might end up spinning many times until by mere chance we make visible the item we were looking for.00:14
thomiheh00:14
elopioI want a test that verifies that we are spinning only the expected number of times.00:14
elopiothomi: but you might be right. It could be that I'm too involved in the current solution that I can't think of an alternate test for this.00:15
elopiolet me know if you have one in mind.00:15
thomiI think I'd do it based on the visible contents perhaps?00:15
elopiook, that could work.00:16
elopiocheck what's the current selected index.00:16
elopiodrag once.00:16
elopiocheck that the selected index is now the old one + 100:16
elopioit's a little harder when the drag is for more than one item at a time, because the toolkit doesn't tell you properly the numer of visible items. But that's a problem for later.00:18
elopiothomi, veebers: thanks! looks better now.00:26
* elopio goes to the gym to become big and strong.00:26
thomielopio: uhh, no worries.00:27
thomididn't realyl do much to help :)00:27
chessin Your first Autopilot test, I am unable to install  libautopilot-qt python-autopilot07:42

Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!