1

I want to check if a function is being called with a string - however it seems that it makes a difference if that string is created using '%s' to insert a substring. The test is failing with this error:

UnexpectedMethodCallError: Unexpected method call.  unexpected:-  expected:+
- foo('Hello %s', 'world') -> None
?            ------
+ foo('Hello world') -> None

How do I check if the method is being called on 'Hello world', regardless of how the string was created?

2 Answers2

1

There is no type or class like "formatted string" in the python. Just string. I think your have error in your code. I mean, it is your fault. I bet you are trying to call it like this:

foo('Hello %s', 'world')

But you should, instead, do

foo('Hello %s' % 'world')

Which will give you expected result.

dt0xff
  • 1,553
  • 1
  • 10
  • 18
1

You should be doing

'Hello %s' % 'world'

There are also a series of comparators that may help you. If you do not care what the value of the string is, then call: mox.IsA(str). You can also do mox.StrContains or mox.Regex to validate further.

RohitJ
  • 543
  • 4
  • 8