Skip to content

Commit e1d602a

Browse files
committed
Fix BuiltIn.Should Not Be Equal
Didn't handle non-string values correctly when `strip_spaces` was set. That situatio should actually be an error, but should then also handle `ignore_case` like that. Related to issue robotframework#3240 and PR robotframework#3843.
1 parent e1b311f commit e1d602a

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

atest/testdata/standard_libraries/builtin/should_be_equal.robot

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -326,49 +326,50 @@ Should Not Be Equal case-insensitive
326326
[Template] Should Not Be Equal
327327
test value TEST VALUE1 ignore_case=True
328328
HYVÄÄ YÖTÄ hyvää yötä1 ignore_case=True
329+
${42} ${43} ignore_case=True
329330
foo FOO ignore_case=True
330331

331332
Should Not Be Equal without leading spaces
332333
[Documentation] FAIL Several failures occurred:
333334
...
334335
... 1) test == test
335336
...
336-
... 2) repr=True: hyvää yötä == hyvää yötä
337+
... 2) hyvää yötä == hyvää yötä
337338
...
338339
... 3) 42 == 42
339340
[Template] Should Not Be Equal
340341
${SPACE}test test strip_spaces=leading
341-
hyvää yötä \nhyvää yötä repr=True strip_spaces=Leading
342-
\t${42} \t${42} strip_spaces=LEADING
342+
hyvää yötä \nhyvää yötä strip_spaces=Leading
343+
${42} ${42} strip_spaces=LEADING
343344
\t\ntest \n\tvalue strip_spaces=leading
344345

345346
Should Not Be Equal without trailing spaces
346347
[Documentation] FAIL Several failures occurred:
347348
...
348349
... 1) test == test
349350
...
350-
... 2) repr=True: hyvää yötä == hyvää yötä
351+
... 2) hyvää yötä == hyvää yötä
351352
...
352353
... 3) 42 == 42
353354
[Template] Should Not Be Equal
354-
test${SPACE} test strip_spaces=trailing
355-
hyvää yötä hyvää yötä\t repr=True strip_spaces=Trailing
356-
${42}\n\t ${42}${SPACE} strip_spaces=TRAILING
355+
test${SPACE} test strip_spaces=trailing
356+
hyvää yötä hyvää yötä\t strip_spaces=Trailing
357+
${42} ${42} strip_spaces=TRAILING
357358
test\t\n value \n strip_spaces=TraIling
358359

359360
Should Not Be Equal without leading and trailing spaces
360361
[Documentation] FAIL Several failures occurred:
361362
...
362363
... 1) test == test
363364
...
364-
... 2) repr=True: hyvää yötä == hyvää yötä
365+
... 2) hyvää yötä == hyvää yötä
365366
...
366367
... 3) 42 == 42
367368
[Template] Should Not Be Equal
368369
test${SPACE} test strip_spaces=True
369-
hyvää yötä hyvää yötä\t repr=True strip_spaces=TRUE
370-
\t${42}\t\n \n${42}\t\n strip_spaces=true
370+
hyvää yötä hyvää yötä\t strip_spaces=TRUE
371371
\ test\t\n \tvalue\t strip_spaces=yeS
372+
${42} ${42} strip_spaces=This probably should be an error.
372373

373374
Should Not Be Equal with bytes containing non-ascii characters
374375
[Documentation] FAIL ${BYTES WITH NON ASCII} == ${BYTES WITH NON ASCII}

src/robot/libraries/BuiltIn.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ def should_not_be_equal(self, first, second, msg=None, values=True,
706706
if is_truthy(ignore_case) and is_string(first) and is_string(second):
707707
first = first.lower()
708708
second = second.lower()
709-
if strip_spaces:
709+
if strip_spaces and is_string(first) and is_string(second):
710710
first = self._strip_spaces(first, strip_spaces)
711711
second = self._strip_spaces(second, strip_spaces)
712712
self._should_not_be_equal(first, second, msg, values)
@@ -806,8 +806,8 @@ def should_be_equal_as_numbers(self, first, second, msg=None, values=True,
806806
second = self._convert_to_number(second, precision)
807807
self._should_be_equal(first, second, msg, values)
808808

809-
def should_not_be_equal_as_strings(self, first, second, msg=None,
810-
values=True, ignore_case=False, strip_spaces=False):
809+
def should_not_be_equal_as_strings(self, first, second, msg=None, values=True,
810+
ignore_case=False, strip_spaces=False):
811811
"""Fails if objects are equal after converting them to strings.
812812
813813
See `Should Be Equal` for an explanation on how to override the default
@@ -839,7 +839,8 @@ def should_not_be_equal_as_strings(self, first, second, msg=None,
839839
self._should_not_be_equal(first, second, msg, values)
840840

841841
def should_be_equal_as_strings(self, first, second, msg=None, values=True,
842-
ignore_case=False, strip_spaces=False, formatter='str'):
842+
ignore_case=False, strip_spaces=False,
843+
formatter='str'):
843844
"""Fails if objects are unequal after converting them to strings.
844845
845846
See `Should Be Equal` for an explanation on how to override the default

0 commit comments

Comments
 (0)