diff --git a/README.md b/README.md index 8c581dfe0887f9702b237b9f68c3e337a4db3c14..af74e923931e5b1fdc7d97bd7937f5ed973fd0ca 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,12 @@ This is an example repository of how Python projects should be organized as at Q On the root of the repository, at minimum you should have: - README.md - LICENSE -- An `.gitignore` file (you can use the one from here as a base template) +- `.gitignore` file (you can use the one from here as a base template) - A single `project_name` directory that contains all the main code - requirements.txt (for the pip requirements) Depending on your project, you might also have: -- y +- `.gitlab-ci.yml` for the CI/CD pipeline ### Code directory Use a simple but meaningful name, as this is the name you're project is going to be imported in case it is packed as a library. @@ -25,8 +25,8 @@ Details of the coding guidelines can be found at the [QIM Gitlab Wiki](https://l In summary: - Use Google style for docstrings. -- Do not add files larger than 32MB, unless stricly necessary. - +- Raise errors when necessary. +- Avoid large files. ## Testing diff --git a/qimex/examples.py b/qimex/examples.py index 288e4845ed5abb28cd7a0bb9b967145750f11a81..b3b8b9297675c8f4d8fa8da206222d7cf1a8b747 100644 --- a/qimex/examples.py +++ b/qimex/examples.py @@ -11,7 +11,10 @@ def say_hello(user): >>> say_hello('Alice') 'Hello Alice!' """ + if not isinstance(user, str): + raise TypeError("The 'user' argument must be a string.") + + greeting = (f'Hello {user}!') - str = (f'Hello {user}!') + return greeting - return str \ No newline at end of file diff --git a/tests/test_examples.py b/tests/test_examples.py index b5c8da1c5bcfb9f999011e2527a3427417c9be2f..0dede1b1175efbec3d3df37dd933367508c0402d 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -1,8 +1,14 @@ import qimex +import pytest def test_say_hello(): - user = "Alice" expected_output = "Hello Alice!" result = qimex.examples.say_hello(user) - assert result == expected_output \ No newline at end of file + assert result == expected_output + +def test_say_hello_with_non_string(): + """ Tests if the correct error is raised""" + user = 123 # Non-string argument + with pytest.raises(TypeError): + qimex.examples.say_hello(user) \ No newline at end of file