Skip to content

Assertion string tweaks#148

Open
Ublius wants to merge 7 commits into
mainfrom
assertion-string-tweaks
Open

Assertion string tweaks#148
Ublius wants to merge 7 commits into
mainfrom
assertion-string-tweaks

Conversation

@Ublius
Copy link
Copy Markdown

@Ublius Ublius commented Apr 6, 2026

Adds diff log highlighting between expected output and current output.

Highlights with green if a character is correct and red if a character is incorrect.\

@gregbell26 let me know if there is anything missing.

@Ublius Ublius requested a review from gregbell26 April 6, 2026 22:51
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 6, 2026

Codecov Report

❌ Patch coverage is 84.21053% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.20%. Comparing base (17e4e0f) to head (ea2036d).

Files with missing lines Patch % Lines
...autograder_platform/TestingFramework/Assertions.py 83.92% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #148      +/-   ##
==========================================
- Coverage   96.68%   96.20%   -0.48%     
==========================================
  Files          26       26              
  Lines        1476     1530      +54     
==========================================
+ Hits         1427     1472      +45     
- Misses         49       58       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Albitr
Copy link
Copy Markdown
Contributor

Albitr commented Apr 6, 2026

How about you don't skill issue it before requesting a review?

@Ublius
Copy link
Copy Markdown
Author

Ublius commented Apr 6, 2026

How about you don't skill issue it before requesting a review?

I already made another skill issue lol DAMIT

Copy link
Copy Markdown
Member

@gregbell26 gregbell26 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good start, needs work.

matcher = difflib.SequenceMatcher(None, expected, actual)

diffLog = []
# maxChars = min(Assertions.DIFF_MAX_CHARACTERS, len(actual), len(expected))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment.

Comment on lines +96 to +99
if visibleCount >= maxChars:
break
diffLog.append(f"{RESET_COLOR}{GREEN_BG}{ch}{RESET_COLOR}")
visibleCount += 1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are repeating this block a lot, break it out into a helper function

if visibleCount >= maxChars:
break

if tag == 'equal':
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think i might prefer pattern matching here - also - are there constants defined for these tags inside the diff tools lib?

return actual

def _assertIterableEqual(self, expected, actual, msg: Optional[str] = None):
errorMsg = msg if msg else None
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is doing nothing - msg will already be none if its not defined.

if expected[i] != actual[i]:
self._raiseFailure("output", expected[i], actual[i], msg)
if isinstance(expected[i], str):
errorMsg = f"Expected output line {i+1} does not match your output line {i+1}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only display the last error message. If we do something like this were we are asserting in a loop, we prolly want to make it display a list of all the lines that dont match

match = re.search(r"Diff Log output: (.*)$", actualMsg, re.DOTALL)
self.assertIsNotNone(match)

diff_log = re.sub(r"\x1b\[[0-9;]*m", "", match.group(1))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for everyone's sanity, you need to either explain this regex in a comment, or assert in a different way.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are missing a bunch of tests. Please add tests for the msg changes that you made. Please add tests covering delete and insert cases for the diff stuff.

errorMsg = f"Incorrect {shortDescription}.\n" + \
f"Expected {shortDescription}: {expectedObject}\n" + \
f"Your {shortDescription} : {actualObject}"
errorMsg = f"Incorrect {shortDescription}.\n"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i almost want to make the diff output configurable. IE you set a flag in the assertions class to enable it or not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default can be on ofc

f"Expected {shortDescription}: {expectedObject}\n" + \
f"Your {shortDescription} : {actualObject}"
errorMsg = f"Incorrect {shortDescription}.\n"
if expectedObject is not None and actualObject is not None and isinstance(expectedObject, str) and isinstance(actualObject, str):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are currently no tests covering this if statement. You need to verify that we dont attempt to use the diff stuff when we arent comparing string to string.

Comment on lines 71 to 72
if msg:
errorMsg += "\n\n" + str(msg)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this interact with the message changes you made later?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants