|
[00:00] <elopio> thomi, 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:02] <elopio> I can't use mock to count the number of time drag was called, because that would do nothing instead of dragging. |
|
[00:02] <elopio> and 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_single |
|
[00:04] <elopio> I'm out of ideas, but I might be missing some simple and straight-forward way to do it. |
|
[00:04] <elopio> thomi, veebers: how would you do it? |
|
[00:05] <veebers> elopio: 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] <thomi> elopio: a decorator? |
|
[00:05] <veebers> I'm sure you acn do it thought, just pondering it |
|
[00:05] <thomi> elopio: make a decorator that counts calls |
|
[00:05] <veebers> thomi: aye, that's what I was thinking, wrap the call and have it count |
|
[00:06] <elopio> thomi, veebers: but then it will count always. Not just for my test. |
|
[00:06] <thomi> elopio: hmmm |
|
[00:07] <veebers> could you have something like: with MethodCaller(object) as smoething:\n\n print something['method_'name'] => 12 |
|
[00:08] <thomi> veebers: but that only works if he controls the call site |
|
[00:08] <thomi> elopio: make your custom proxy class count the calls only when it's been enabled with a context manager |
|
[00:08] <thomi> so you'd do: |
|
[00:08] <elopio> I didn't get that. |
|
[00:08] <thomi> with my_custom_proxy_class_instance.count_calls(): |
|
[00:08] <thomi> # test code |
|
[00:08] <thomi> assert my_custom_proxy_class_instance.call_count == 12 |
|
[00:08] <elopio> I mean, the methodcaller solution. |
|
[00:10] <elopio> thomi: ok, I don't like that, but I guess I'll go with it. |
|
[00:10] <thomi> elopio: it's quite an unusual requirement |
|
[00:11] <elopio> my ideal solution was something like mock.patch(CustomProxyObj, 'slow_drag'), so I didn't have to touch the original class |
|
[00:12] <elopio> but instead of patching it with a mock, it keeps the same slow_drag implementation but records the call_count. |
|
[00:12] <thomi> elopio: why do you want this? There's probably a better way |
|
[00:12] <thomi> counting the number of calls seems like you're testing the wrong thing TBH |
|
[00:12] <elopio> I'll propose it to mfoord, charge a cent for everybody who uses it, and then I will earn one cent. |
|
[00:13] <elopio> thomi: on the qquicklistviews we have to drag the list many times in order to find items, right? |
|
[00:13] <elopio> I'm now working with circular lists |
|
[00:13] <elopio> if we drag too fast, we skip some items |
|
[00:14] <elopio> but 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] <thomi> heh |
|
[00:14] <elopio> I want a test that verifies that we are spinning only the expected number of times. |
|
[00:15] <elopio> thomi: 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] <elopio> let me know if you have one in mind. |
|
[00:15] <thomi> I think I'd do it based on the visible contents perhaps? |
|
[00:16] <elopio> ok, that could work. |
|
[00:16] <elopio> check what's the current selected index. |
|
[00:16] <elopio> drag once. |
|
[00:16] <elopio> check that the selected index is now the old one + 1 |
|
[00:18] <elopio> it'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:26] <elopio> thomi, veebers: thanks! looks better now. |
|
[00:26] * elopio goes to the gym to become big and strong. |
|
[00:27] <thomi> elopio: uhh, no worries. |
|
[00:27] <thomi> didn't realyl do much to help :) |
|
[07:42] <chess> in Your first Autopilot test, I am unable to install libautopilot-qt python-autopilot |
|
|