Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new synchronous assertions #20

Merged
merged 2 commits into from
Jan 12, 2025
Merged

Add new synchronous assertions #20

merged 2 commits into from
Jan 12, 2025

Conversation

douglasdcm
Copy link
Owner

Add synchronous assertions 'HasKeyValue', 'MatchesRegex', 'HasSubset', 'IsSorted'

@douglasdcm douglasdcm merged commit a21087b into main Jan 12, 2025
2 of 3 checks passed
@douglasdcm douglasdcm deleted the add-builtin-assertions branch January 13, 2025 00:28
Copy link
Collaborator

@Rahat-karim Rahat-karim left a comment

Choose a reason for hiding this comment

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

The Calculator class is imported twice from different paths. You should remove one of the imports to avoid redundancy.
from calculator import Calculator # Keep this one

Remove the second import

suggested code changes
import random
from calculator import Calculator
from examples.unit_test import calculator_transactions
from examples.unit_test.calculator import operations
from guara.transaction import Application
from guara import it

class TestCalculator:
def setup_method(self, method):
"""Set up the application instances for each test method."""
self._app = Application(Calculator)
self._calculator = Application(Calculator())

def test_add_returns_3_when_adding_1_and_2(self):
    """Test that adding 1 and 2 returns 3."""
    self._app.at(calculator_transactions.Add, a=1, b=2).asserts(it.IsEqualTo, 3)
    self._calculator.at(operations.Add, a=1, b=2).asserts(it.IsEqualTo, 3)

def test_add_returns_1_when_adding_1_and_0(self):
    """Test that adding 1 and 0 returns 1."""
    self._app.at(calculator_transactions.Add, a=1, b=0).asserts(it.IsEqualTo, 1)
    self._calculator.at(operations.Add, a=1, b=0).asserts(it.IsEqualTo, 1)

def test_subtract_returns_1_when_subtracting_1_from_2(self):
    """Test that subtracting 1 from 2 returns 1."""
    self._app.at(calculator_transactions.Subtract, a=2, b=1).asserts(it.IsEqualTo, 1)
    self._calculator.at(operations.Subtract, a=2, b=1).asserts(it.IsEqualTo, 1)

By implementing the suggested improvements, you can enhance readability, maintainability, and clarity of the tests. Always ensure that your tests are clear and provide meaningful feedback when they fail, as this will help in debugging and maintaining the code in the long run.
but the code is structured well for a testing framework.

@douglasdcm
Copy link
Owner Author

Thanks @Rahat-karim for the suggestions. I'll make the changes. Feel free to open new issues and PRs.

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.

2 participants