Init template for scripts.
This commit is contained in:
commit
621477c97b
70
scripts/templates/my_script.py
Normal file
70
scripts/templates/my_script.py
Normal file
|
@ -0,0 +1,70 @@
|
|||
######################################################################
|
||||
# Copyright (c) Boris Baldassari, Adrien Luxey-Bitri
|
||||
#
|
||||
# This program and the accompanying materials are made
|
||||
# available under the terms of the Eclipse Public License 2.0
|
||||
# which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
#
|
||||
# SPDX-License-Identifier: EPL-2.0
|
||||
######################################################################
|
||||
|
||||
import argparse
|
||||
from pprint import pprint
|
||||
|
||||
"""
|
||||
This module provides a set of example functions.
|
||||
|
||||
See also the tests for the module, located in test_my_script.py.
|
||||
Run tests with `pytest test_my_script`:
|
||||
$ pytest test_my_script.py -vvvv
|
||||
======================== test session starts ========================
|
||||
platform linux -- Python 3.11.2, pytest-7.2.1, pluggy-1.0.0+repack -- /usr/bin/python3
|
||||
cachedir: .pytest_cache
|
||||
rootdir: /home/user/project/scripts/templates
|
||||
collected 1 item
|
||||
|
||||
test_my_script.py::test_add_integers_case0 PASSED [100%]
|
||||
|
||||
========================= 1 passed in 0.00s =========================
|
||||
|
||||
"""
|
||||
|
||||
|
||||
def _parse_args():
|
||||
"""
|
||||
Parse arguments from command line.
|
||||
"""
|
||||
parser = argparse.ArgumentParser(description="A script that does something.")
|
||||
parser.add_argument('-wg', '--working_group',
|
||||
help='Retrieve information for all projects in a working group.')
|
||||
parser.add_argument('-p', '--project',
|
||||
help='Retrieve information for a single project ID.')
|
||||
parser.add_argument('-c', '--conf',
|
||||
help='Configuration file for opensearch access.')
|
||||
args = parser.parse_args()
|
||||
return args
|
||||
|
||||
|
||||
def add_ints(a: int, b: int):
|
||||
"""
|
||||
Adds two integers and returns the outcome.
|
||||
|
||||
Returns
|
||||
|
||||
Parameters:
|
||||
|
||||
- `a`: First integer to add.
|
||||
- `b`: Second integer to add.
|
||||
"""
|
||||
print('Printed from add_ints function.')
|
||||
return a + b
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
# Parse command-line arguments
|
||||
args = _parse_args()
|
||||
pprint(args)
|
||||
|
||||
|
||||
|
31
scripts/templates/test_my_script.py
Normal file
31
scripts/templates/test_my_script.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
######################################################################
|
||||
# Copyright (c) Boris Baldassari, Adrien Luxey-Bitri
|
||||
#
|
||||
# This program and the accompanying materials are made
|
||||
# available under the terms of the Eclipse Public License 2.0
|
||||
# which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
#
|
||||
# SPDX-License-Identifier: EPL-2.0
|
||||
######################################################################
|
||||
|
||||
import pytest
|
||||
from pprint import pprint
|
||||
|
||||
import my_script as target
|
||||
|
||||
"""
|
||||
Script to test the my_script.py module.
|
||||
|
||||
Use with `pytest test_my_script.py -v`.
|
||||
"""
|
||||
|
||||
def test_add_integers_case1():
|
||||
""" Tests add_integer. """
|
||||
assert target.add_ints(2, 3) == 5
|
||||
assert target.add_ints(6, 0) == 6
|
||||
assert target.add_ints(0, 7) == 7
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in a new issue