You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add mechanism to permit to mock generic methods/functions of the python package
The new `ApiMocker.mockable` is a decorator that can be applied to mock any method.
The decorator will automatically search in the `<function-name-path>.overrides.py` file (if it exists)
a function with the same name of the function.
If the function exists, the decorator will execute it in place of the original one.
The same `slurm_plugin.overrides.py` file is already used by `run_instances` and `create_fleet` methods,
but without the generic decorator mechanism. We can use this new mechanism for them in the future.
I'm using it for `describe_capacity_reservations` to permit to mock it when running e2e tests.
An example of bash script to create overrides file is:
```
node_virtualenv_path=$(sudo find / -iname "site-packages" | grep "node_virtualenv")
# the overrides.py file must be in the same folder of the module of the function to be mocked
cat << EOF | sudo tee -a "${node_virtualenv_path}/aws/overrides.py"
from aws.ec2 import CapacityReservationInfo
def describe_capacity_reservations(_, capacity_reservations_ids):
return [
CapacityReservationInfo({
"CapacityReservationId": "cr-123456",
"OwnerId": "123456789",
"CapacityReservationArn": "arn:aws:ec2:us-east-2:123456789:capacity-reservation/cr-123456",
...
})
]
EOF
```
### Tests
Tested with:
* not existing overrides.py (`ImportError`)
* empty overrides.py (`AttributeError`)
* overrides.py with other functions defined on it (`AttributeError`)
* overrides.py with the mocked `describe_capacity_reservations` (mocked output)
Signed-off-by: Enrico Usai <[email protected]>
0 commit comments