This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: dagger CI | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
ci: | |
runs-on: ubuntu-latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ci | |
import ( | |
"dagger.io/dagger" | |
"universe.dagger.io/bash" // import this package to execute bash commands inside a docker container | |
"universe.dagger.io/docker" // import this package to set up docker | |
) | |
dagger.#Plan & { | |
// configure the client so that dagger takes only the files it needs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@pytest.mark.parametrize( | |
"test_input, expected", | |
[ | |
("[email protected]", True), | |
("[email protected]", True), | |
("[email protected]", True), | |
("inavlid.com", False), | |
("veryb@[email protected]", False), | |
("[email protected]", False) | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_valid_email_address(email: str) -> bool: | |
regex = "^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$" | |
return re.search(regex, email) is not None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@pytest.mark.freeze_time("2020-01-15 13:00:00") | |
def test_get_time_since_subscription(): | |
test_subscribtion_date = datetime.datetime(2020, 1, 10, 12) | |
assert get_time_since_subscription(test_subscribtion_date) == 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_time_since_subscription(subscription_date: datetime.datetime) -> int: | |
current_date = datetime.datetime.utcnow() | |
return (current_date - subscription_date).days |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_email_validation(): | |
with pytest.raises(InvalidEmailAddressError): | |
assert validate_email_address(None, None, "invalid.com") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InvalidEmailAddressError(Exception): | |
pass | |
def validate_email_address(ctx, param, value): | |
regex = "^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$" | |
if not re.search(regex, value): | |
raise InvalidEmailAddressError(f"Invalid email address: {value}") | |
return value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_translate_animal_names(caplog): | |
animals_in_french = ["lapin", "grenouille", "cheval"] | |
french_english_translation = { | |
"lapin": "rabbit", | |
"cheval": "horse" | |
} | |
animals_in_english = translate_animal_names( | |
animals_in_french, | |
french_english_translation | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def translate_animal_names( | |
animals: List[str], | |
translations: Dict[str, str] | |
) -> List[str]: | |
translated_animal_names = [] | |
for animal in animals: | |
if animal in translations: | |
translated_animal_names.append(translations[animal]) | |
else: | |
logging.warning( |
NewerOlder