Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test failures on main #82

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
Expand All @@ -39,6 +39,11 @@ jobs:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Check types with mypy
run: |
python3 -m pip install mypy
andreww marked this conversation as resolved.
Show resolved Hide resolved
python3 -m pip install types-PyYAML types-redis types-requests types-ujson
python3 -m mypy cats
- name: Test with pytest
run: |
python3 -m pytest
7 changes: 4 additions & 3 deletions cats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def to_json(self, dateformat: str = "", **kwargs) -> str:
def schedule_at(output: CATSOutput, args: list[str]) -> None:
"Schedule job with optimal start time using at(1)"
proc = subprocess.Popen(args, stdout=subprocess.PIPE)
output = subprocess.check_output(
proc_output = subprocess.check_output(
(
"at",
"-t",
Expand All @@ -206,7 +206,7 @@ def schedule_at(output: CATSOutput, args: list[str]) -> None:
)


def main(arguments=None) -> Optional[int]:
def main(arguments=None) -> int:
parser = parse_arguments()
args = parser.parse_args(arguments)
if args.command and not args.scheduler:
Expand All @@ -215,7 +215,7 @@ def main(arguments=None) -> Optional[int]:
" specify the scheduler with the -s or --scheduler option"
)
return 1
config, CI_API_interface, location, duration = get_runtime_config(args)
config, CI_API_interface, location, duration, _jobinfo, _PUE = get_runtime_config(args)

########################
## Obtain CI forecast ##
Expand Down Expand Up @@ -272,6 +272,7 @@ def main(arguments=None) -> Optional[int]:
print(output)
if args.command and args.scheduler == "at":
schedule_at(output, args.command.split())
return 0


if __name__ == "__main__":
Expand Down
10 changes: 6 additions & 4 deletions cats/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import logging
import sys
from collections.abc import Mapping
from typing import Any
from typing import Any, Union

import requests
import yaml
Expand All @@ -24,7 +24,8 @@
__all__ = ["get_runtime_config"]


def get_runtime_config(args) -> tuple[dict, APIInterface, str, int]:
def get_runtime_config(args) -> tuple[Mapping[str, Any], APIInterface, str, int,
Union[list[tuple[int, float]],None],Any]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one of these cases where typing really isn't worth the trouble in my opinion.

"""Return the runtime cats configuration from list of command line
arguments and content of configuration file.

Expand All @@ -47,7 +48,7 @@ def get_runtime_config(args) -> tuple[dict, APIInterface, str, int]:
try:
duration = int(args.duration)
except ValueError:
logging.eror(msg)
logging.error(msg)
raise ValueError
if duration <= 0:
logging.error(msg)
Expand Down Expand Up @@ -91,13 +92,14 @@ def CI_API_from_config_or_args(args, config) -> APIInterface:
api = "carbonintensity.org.uk" # default value
logging.warning(f"Unspecified carbon intensity forecast service, using {api}")
try:
return API_interfaces[api]
interface = API_interfaces[api]
except KeyError:
logging.error(
f"Error: {api} is not a valid API choice. It must be one of " "\n".join(
API_interfaces.keys()
)
)
return interface


def get_location_from_config_or_args(args, config) -> str:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
@pytest.mark.parametrize(
"output,expected",
[
(OUTPUT, "Best job start time: 2024-03-16 02:00:00"),
(OUTPUT, "Best job start time: 2024-03-16 02:00:00\n"),
(
OUTPUT_WITH_EMISSION_ESTIMATE,
"""Best job start time: 2024-03-16 02:00:00

Estimated emmissions for running job now: 19
Estimated emmissions for running delayed job: 9 (- 10)""",
),
Expand Down