Time for action – comparing strings
Let's compare strings. Both strings are the word "NumPy"
:
Call the
assert_string_equal
function to compare a string with itself. This test, of course, should pass:print "Pass", np.testing.assert_string_equal("NumPy", "NumPy")
The test passes:
Pass None
Call the
assert_string_equal
function to compare a string with another string with the same letters but different casing. This test should throw an exception:print "Fail", np.testing.assert_string_equal("NumPy", "Numpy")
An exception is thrown:
Fail Traceback (most recent call last): … raiseAssertionError(msg) AssertionError: Differences in strings: - NumPy? ^ + Numpy? ^
What just happened?
We compared two strings with the assert_string_equal
function. The test threw an exception when the casing did not match.