Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/test_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ def test_divide():
assert Calculator.divide(0, 2.0) == 0
assert Calculator.divide(-4, 2.0) == -2.0
# assert Calculator.divide(2.0, 0.0) == 'Cannot divide by 0'

def test_add2():
# Test that add2 function raises NameError due to undefined variable 'z'
with pytest.raises(NameError, match="name 'z' is not defined"):
Comment on lines +34 to +35
Copy link

Choose a reason for hiding this comment

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

The test expects a NameError with the message "name 'z' is not defined", but this doesn't make sense in the context of testing a calculator method. This suggests the test is either:

  1. Testing some internal implementation detail that references an undefined variable 'z'
  2. Copy-pasted from another context
  3. Not properly designed for the intended functionality

Tests should focus on the public API and expected behavior, not internal implementation errors.

Suggested change
# Test that add2 function raises NameError due to undefined variable 'z'
with pytest.raises(NameError, match="name 'z' is not defined"):
# Test should focus on expected behavior, for example:
# with pytest.raises(TypeError, match="missing 1 required positional argument"):
# Calculator.add(1) # Missing second argument

Did we get this right? 👍 / 👎 to inform future reviews.

Calculator.add2(1, 2)
Comment on lines +33 to +36
Copy link
Author

Choose a reason for hiding this comment

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

The test is attempting to call Calculator.add2() which doesn't exist in the Calculator class. Based on the calculator.py file, there is no add2 method defined. This test will fail with an AttributeError before it can test for the expected NameError. Either implement the add2 method in the Calculator class or remove this test if it's not needed.

Suggested change
def test_add2():
# Test that add2 function raises NameError due to undefined variable 'z'
with pytest.raises(NameError, match="name 'z' is not defined"):
Calculator.add2(1, 2)
# Either implement Calculator.add2() method or remove this test
# If testing error handling, ensure the method exists first

Did we get this right? 👍 / 👎 to inform future reviews.

Calculator.add2(0, 0)
Comment on lines +33 to +37

Choose a reason for hiding this comment

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

The test is attempting to call Calculator.add2(), but this method does not exist in the Calculator class. This will result in an AttributeError: type object 'Calculator' has no attribute 'add2' instead of the expected NameError. The test should either be updated to test an existing method that contains an undefined variable, or the corresponding add2 method should be implemented in the Calculator class first.

Suggested change
def test_add2():
# Test that add2 function raises NameError due to undefined variable 'z'
with pytest.raises(NameError, match="name 'z' is not defined"):
Calculator.add2(1, 2)
Calculator.add2(0, 0)
# First implement the add2 method in Calculator class, or update this test to use an existing method
# Example if add2 method exists:
# def test_add2():
# with pytest.raises(NameError, match="name 'z' is not defined"):
# Calculator.add2(1, 2)

Did we get this right? 👍 / 👎 to inform future reviews.

Choose a reason for hiding this comment

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

hmmm

Choose a reason for hiding this comment

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

Actually in our team, we put all functions in a utils.py file

Comment on lines +33 to +37
Copy link

Choose a reason for hiding this comment

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

The test test_add2() is attempting to test a method Calculator.add2() that doesn't exist in the Calculator class. Based on the calculator.py file, there is no add2 method defined. This test will fail with an AttributeError because the method doesn't exist, not a NameError as expected. You should either:

  1. Implement the add2 method in the Calculator class if it's intended functionality
  2. Remove this test if it's not needed
  3. Fix the test to call an existing method if this was a typo
Suggested change
def test_add2():
# Test that add2 function raises NameError due to undefined variable 'z'
with pytest.raises(NameError, match="name 'z' is not defined"):
Calculator.add2(1, 2)
Calculator.add2(0, 0)
# If you intended to test the existing 'add' method:
def test_add2():
# Test additional scenarios for the add function
assert Calculator.add(5, 7) == 12
assert Calculator.add(-1, 1) == 0
assert Calculator.add(0.5, 0.5) == 1.0

Did we get this right? 👍 / 👎 to inform future reviews.