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 precommit #98

Merged
merged 5 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Lint

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
with:
options: "--check -l 100"
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
repos:
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
args: [--line-length=100]
language_version: python3.11
8 changes: 8 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ pip install -r requirements.txt -r test-requirements.txt
Fork this repository, make the changes into the forked repository and push a new Merge Request to 'main' branch.
Open an issue in case of big MRs.

## Install pre-commit

It formats the code on each commit.

```
pre-commit install
```

## Testing

```
Expand Down
4 changes: 1 addition & 3 deletions examples/mobile/appium/test_appium_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,5 @@ def teardown_method(self, method):
def test_local_page(self):
text = ["cheese", "appium", "test", "bla", "foo"]
text = text[randrange(len(text))]
self._app.at(SubmitTextAppium, text=text).asserts(
it.IsEqualTo, f"It works! {text}!"
)
self._app.at(SubmitTextAppium, text=text).asserts(it.IsEqualTo, f"It works! {text}!")
self._app.at(SubmitTextAppium, text=text).asserts(it.IsNotEqualTo, "Any")
4 changes: 1 addition & 3 deletions examples/prototyping/todo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,4 @@ def get_task(event):
index = 0
index = int(index)
# index = int(value) - 1
document.querySelector("#output").innerText = app.at(
transactions.GetBy, index=index
).result
document.querySelector("#output").innerText = app.at(transactions.GetBy, index=index).result
1 change: 1 addition & 0 deletions examples/unit_test/async_todo_list/async_todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
The module that will have the class where the tasks will be
stored.
"""

from typing import List, Dict


Expand Down
6 changes: 6 additions & 0 deletions examples/unit_test/async_todo_list/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
The module that have all of the transactions needed for the
To-Do List.
"""

from guara.asynchronous.transaction import AbstractTransaction
from examples.unit_test.async_todo_list.async_todo import AsyncToDo
from typing import Any, List, Dict
Expand All @@ -11,6 +12,7 @@ class Add(AbstractTransaction):
"""
The addition transaction
"""

def __init__(self, driver: Any):
"""
Initializing the transaction.
Expand All @@ -29,6 +31,7 @@ class Remove(AbstractTransaction):
"""
The removal transaction.
"""

def __init__(self, driver: Any):
"""
Initializing the transaction.
Expand All @@ -47,6 +50,7 @@ class ListTasks(AbstractTransaction):
"""
The listing transaction
"""

def __init__(self, driver: Any):
"""
Initializing the transaction.
Expand All @@ -65,6 +69,7 @@ class PrintDict(AbstractTransaction):
"""
The array to object conversion transaction.
"""

def __init__(self, driver: Any):
"""
Initializing the transaction.
Expand All @@ -83,6 +88,7 @@ class GetBy(AbstractTransaction):
"""
The transaction which will get a specific task by its index.
"""

def __init__(self, driver: Any):
"""
Initializing the transaction.
Expand Down
16 changes: 4 additions & 12 deletions examples/unit_test/async_todo_list/test_async_todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,10 @@ async def test_async_add_task(self, setup_test: Coroutine[Any, Any, None]) -> No
"""
task: str = "buy cheese"
expected: List[str] = [task]
await self._todo.at(transaction=Add, task=task).asserts(
IsEqualTo, expected
).perform()
await self._todo.at(transaction=Add, task=task).asserts(IsEqualTo, expected).perform()

@mark.asyncio
async def test_async_remove_task(
self, setup_test: Coroutine[Any, Any, None]
) -> None:
async def test_async_remove_task(self, setup_test: Coroutine[Any, Any, None]) -> None:
"""
Testing the remove task transaction.

Expand All @@ -60,14 +56,10 @@ async def test_async_remove_task(
task: str = "buy cheese"
expected: List[str] = []
await self._todo.at(transaction=Add, task=task).perform()
await self._todo.at(transaction=Remove, task=task).asserts(
IsEqualTo, expected
).perform()
await self._todo.at(transaction=Remove, task=task).asserts(IsEqualTo, expected).perform()

@mark.asyncio
async def test_async_list_tasks(
self, setup_test: Coroutine[Any, Any, None]
) -> None:
async def test_async_list_tasks(self, setup_test: Coroutine[Any, Any, None]) -> None:
"""
Testing the listing of the tasks transaction.

Expand Down
4 changes: 1 addition & 3 deletions examples/web_ui/browserist/test_browserist_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,5 @@ def teardown_method(self, method):
def test_local_page(self):
text = ["cheese", "selenium", "test", "bla", "foo"]
text = text[randrange(len(text))]
self._app.at(home.SubmitText, text=text).asserts(
it.IsEqualTo, f"It works! {text}!"
)
self._app.at(home.SubmitText, text=text).asserts(it.IsEqualTo, f"It works! {text}!")
self._app.at(home.SubmitText, text=text).asserts(it.IsNotEqualTo, "Any")
4 changes: 1 addition & 3 deletions examples/web_ui/helium/test_helium_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,5 @@ def teardown_method(self, method):
def test_local_page(self):
text = ["cheese", "selenium", "test", "bla", "foo"]
text = text[randrange(len(text))]
self._app.at(home.SubmitText, text=text).asserts(
it.IsEqualTo, f"It works! {text}!"
)
self._app.at(home.SubmitText, text=text).asserts(it.IsEqualTo, f"It works! {text}!")
self._app.at(home.SubmitText, text=text).asserts(it.IsNotEqualTo, "Any")
4 changes: 1 addition & 3 deletions examples/web_ui/playwright/test_web_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ def setup_method(page: Page):
def test_local_page_playwright(setup_method):
dev_page: Application = setup_method
dev_page.at(home.NavigateToGettingStarted).asserts(it.IsEqualTo, "Installation")
dev_page.at(getting_started.NavigateToWritingTests).asserts(
it.IsNotEqualTo, "Writing Tests"
)
dev_page.at(getting_started.NavigateToWritingTests).asserts(it.IsNotEqualTo, "Writing Tests")
4 changes: 1 addition & 3 deletions examples/web_ui/selenium/advanced/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ def wait_search(self, wait_for):
wait_for,
)
)
return self._driver.find_element(
By.CSS_SELECTOR, ".row:nth-child(1) > .col-md-2 > p"
).text
return self._driver.find_element(By.CSS_SELECTOR, ".row:nth-child(1) > .col-md-2 > p").text

def do(self, text, wait_for):
self.fill_text(text)
Expand Down
16 changes: 7 additions & 9 deletions examples/web_ui/selenium/advanced/test_external_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def test_vpm_transaction_chain(self):
content_in_english = "Content of curriculum"
content_in_portuguese = "Conteúdo do currículo"

self._app.at(home.ChangeToPortuguese).asserts(
it.IsEqualTo, content_in_portuguese
)
self._app.at(home.ChangeToPortuguese).asserts(it.IsEqualTo, content_in_portuguese)
# uses native assertion
result = self._app.at(home.ChangeToEnglish).result
it.IsEqualTo().asserts(result, content_in_english)
Expand All @@ -43,13 +41,13 @@ def test_vpm_transaction_chain(self):
it.IsEqualTo, "Contact us. We would be happy to answer your questions."
)
self._app.at(home.NavigateTo).asserts(it.IsEqualTo, content_in_english)
self._app.at(
home.DoRestrictedSearch, text=text, wait_for=restricted_similariy
).asserts(it.IsEqualTo, restricted_similariy)
self._app.at(home.DoRestrictedSearch, text=text, wait_for=restricted_similariy).asserts(
it.IsEqualTo, restricted_similariy
)
self._app.at(home.NavigateTo).asserts(it.IsEqualTo, content_in_english)
self._app.at(
home.DoExpandedSearch, text=text, wait_for=expanded_similarity
).asserts(it.IsEqualTo, expanded_similarity)
self._app.at(home.DoExpandedSearch, text=text, wait_for=expanded_similarity).asserts(
it.IsEqualTo, expanded_similarity
)
self._app.at(home.NavigateTo).asserts(it.IsEqualTo, content_in_english)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,5 @@ def teardown_method(self, method):
def test_local_page(self):
text = ["cheese", "selenium", "test", "bla", "foo"]
text = text[randrange(len(text))]
self._app.at(home.SubmitText, text=text).asserts(
it.IsEqualTo, f"It works! {text}!"
)
self._app.at(home.SubmitText, text=text).asserts(it.IsEqualTo, f"It works! {text}!")
self._app.at(home.SubmitText, text=text).asserts(it.IsNotEqualTo, "Any")
4 changes: 1 addition & 3 deletions examples/web_ui/splinter/test_splinter_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,5 @@ def teardown_method(self, method):
def test_local_page(self):
text = ["cheese", "splinter", "test", "bla", "foo"]
text = text[random.randrange(len(text))]
self._app.at(home.SubmitTextSplinter, text=text).asserts(
it.IsEqualTo, f"It works! {text}!"
)
self._app.at(home.SubmitTextSplinter, text=text).asserts(it.IsEqualTo, f"It works! {text}!")
self._app.at(home.SubmitTextSplinter, text=text).asserts(it.IsNotEqualTo, "Any")
2 changes: 2 additions & 0 deletions guara/abstract_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
It is the module where the AbstractTransaction will handle
web transactions in an automated browser.
"""

from typing import Any, NoReturn, Union, Dict


class AbstractTransaction:
"""
It will handle web transactions in an automated browser.
"""

def __init__(self, driver: Any):
"""
Initializing the transaction which will allow it to interact
Expand Down
1 change: 1 addition & 0 deletions guara/assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
The module that has the interface for the implmentation of
the assertion logic to be used for validation and testing.
"""

from typing import Any
from logging import getLogger, Logger

Expand Down
2 changes: 2 additions & 0 deletions guara/asynchronous/abstract_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
It is the module where the interface of the transaction will
handle web transactions in an automated browser.
"""

from typing import Any, NoReturn, Union, Dict


class AbstractTransaction:
"""
It will handle web transactions in an automated browser.
"""

@property
def __name__(self) -> property:
"""
Expand Down
5 changes: 5 additions & 0 deletions guara/asynchronous/it.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
The module that deals with the assertion and validation of a
transaction at the runtime.
"""

from typing import Any
from guara.asynchronous.assertion import IAssertion
from logging import getLogger, Logger
Expand All @@ -14,6 +15,7 @@ class IsEqualTo(IAssertion):
"""
Equality Assertion class
"""

async def asserts(self, actual: Any, expected: Any) -> None:
assert actual.result == expected

Expand All @@ -22,6 +24,7 @@ class IsNotEqualTo(IAssertion):
"""
Not Equality Assertion class
"""

async def asserts(self, actual: Any, expected: Any) -> None:
assert actual.result != expected

Expand All @@ -30,6 +33,7 @@ class Contains(IAssertion):
"""
Containing Assertion class
"""

async def asserts(self, actual: Any, expected: Any) -> None:
assert expected in actual.result

Expand All @@ -38,5 +42,6 @@ class DoesNotContain(IAssertion):
"""
Not Containing Assertion class
"""

async def asserts(self, actual: Any, expected: Any) -> None:
assert expected not in actual.result
3 changes: 2 additions & 1 deletion guara/asynchronous/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
The module that is reponsible for the opening and closing
transactions.
"""

from guara.asynchronous.transaction import AbstractTransaction
from typing import Dict, Any

Expand Down Expand Up @@ -45,7 +46,7 @@ class CloseApp(AbstractTransaction):
https://github.com/douglasdcm/caqui
"""

def __init__(self, driver: (Any)):
def __init__(self, driver: Any):
"""
Initializing the transaction

Expand Down
16 changes: 3 additions & 13 deletions guara/asynchronous/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ def result(self) -> Any:
"""
return self._result

def at(
self,
transaction: AbstractTransaction,
**kwargs: Dict[str, Any]
) -> "Application":
def at(self, transaction: AbstractTransaction, **kwargs: Dict[str, Any]) -> "Application":
"""
Executing each transaction.

Expand Down Expand Up @@ -120,11 +116,7 @@ async def perform(self) -> "Application":
(Application)
"""
for index in range(0, len(self._coroutines), 1):
(
await self.get_assertion(index)
if not await self.get_transaction(index)
else None
)
(await self.get_assertion(index) if not await self.get_transaction(index) else None)
self._coroutines.clear()
return self

Expand All @@ -138,9 +130,7 @@ async def get_transaction(self, index: int) -> bool:
Returns:
(bool)
"""
transaction: Coroutine[None, None, Any] = self._coroutines[index].get(
self._TRANSACTION
)
transaction: Coroutine[None, None, Any] = self._coroutines[index].get(self._TRANSACTION)
if transaction:
LOGGER.info(f"Transaction: {self._transaction_name}")
for key, value in self._kwargs.items():
Expand Down
4 changes: 1 addition & 3 deletions guara/it.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ class MatchesRegex(IAssertion):
def asserts(self, actual: str, expected: str) -> None:
if match(expected, actual):
return
raise AssertionError(
"The actual data does not match the expected regular expression."
)
raise AssertionError("The actual data does not match the expected regular expression.")


class HasSubset(IAssertion):
Expand Down
4 changes: 1 addition & 3 deletions guara/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,5 @@ def __init__(self, driver: Any):
super().__init__(driver)

def do(self, screenshot_filename: str = "./captures/guara-capture") -> None:
self._driver.get_screenshot_as_file(
f"{screenshot_filename}-{datetime.now()}.png"
)
self._driver.get_screenshot_as_file(f"{screenshot_filename}-{datetime.now()}.png")
self._driver.quit()
4 changes: 1 addition & 3 deletions guara/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ def result(self) -> Any:
"""
return self._result

def at(
self, transaction: AbstractTransaction, **kwargs: Dict[str, Any]
) -> "Application":
def at(self, transaction: AbstractTransaction, **kwargs: Dict[str, Any]) -> "Application":
"""
Performing a transaction.

Expand Down
Loading