Skip to content
Snippets Groups Projects
Commit 6c979d4d authored by Felipe Delestro Matos's avatar Felipe Delestro Matos
Browse files

updated tests

parent 56e4301c
Branches
No related tags found
No related merge requests found
...@@ -9,6 +9,9 @@ On the root of the repository, at minimum you should have: ...@@ -9,6 +9,9 @@ On the root of the repository, at minimum you should have:
- A single `project_name` directory that contains all the main code - A single `project_name` directory that contains all the main code
- requirements.txt (for the pip requirements) - requirements.txt (for the pip requirements)
Depending on your project, you might also have:
- y
### Code directory ### 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. 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.
...@@ -16,6 +19,9 @@ Here we use `qimex` as in **QIM** **Ex**ample ...@@ -16,6 +19,9 @@ Here we use `qimex` as in **QIM** **Ex**ample
## Coding guidelines ## Coding guidelines
Details of the coding guidelines can be found at the QIM Gitlab Wiki:
https://lab.compute.dtu.dk/groups/QIM/-/wikis/Home/Coding-standards
## Testing ## Testing
We should use `pytest` to manage unit testing of the repository. We should use `pytest` to manage unit testing of the repository.
......
def say_hello(user): def say_hello(user):
"""Prints a greeting message to the specified user. """Generates a greeting message for the specified user.
Args: Args:
user (str): The name of the user to greet. user (str): The name of the user.
Returns: Returns:
None str: The greeting message.
Example: Example:
>>> say_hello('Alice') >>> say_hello('Alice')
Hello Alice! 'Hello Alice!'
""" """
print (f'Hello {user}!')
str = (f'Hello {user}!')
return str
\ No newline at end of file
import qimex import qimex
from io import StringIO
import sys
def test_say_hello(): def test_say_hello():
# Redirect standard output to a StringIO object user = "Alice"
captured_output = StringIO() expected_output = "Hello Alice!"
sys.stdout = captured_output result = qimex.examples.say_hello(user)
assert result == expected_output
# Call the function to test \ No newline at end of file
qimex.examples.say_hello('Alice')
# Restore the standard output
sys.stdout = sys.__stdout__
# Get the captured output
output = captured_output.getvalue().strip()
# Assert that the expected output is printed to the console
assert output == 'Hello Alice!'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment