Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Add flake8-quotes. Reformat code with double-quotes style. (#68)
Browse files Browse the repository at this point in the history
* Add flake8-quotes

* Add double-quotes checker

* Format to double quotes

* Format to double quotes

* Remove useless test.

* Force line-length=120

* Force line-length < 120

* Use only double quotes
  • Loading branch information
kagrski authored Dec 21, 2022
1 parent 262c614 commit 7215f32
Show file tree
Hide file tree
Showing 33 changed files with 628 additions and 491 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
- name: Check static-typing
run: poetry run mypy --show-error-codes --show-error-context --pretty --install-types --non-interactive vmngclient
- name: Check code style
run: poetry run flake8 --max-line-length 120 vmngclient
run: poetry run flake8 --max-line-length 120 --inline-quotes double vmngclient
7 changes: 5 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ repos:
rev: 22.8.0
hooks:
- id: black
args: ["-l", "120", "-S"]
args: ["-l", "120"]

# Code analysis (only checks staged files)

Expand All @@ -50,4 +50,7 @@ repos:
rev: 5.0.4
hooks:
- id: flake8
args: ["--max-line-length", "120"]
additional_dependencies: [
"flake8-quotes==3.3.2"
]
args: ["--max-line-length", "120", "--inline-quotes", "double"]
22 changes: 17 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ciscoconfparse = "^1.6.40"
tenacity = "^8.1.0"
parameterized = "^0.8.1"
Jinja2 = "^3.1.2"
flake8-quotes = "^3.3.1"

[tool.poetry.dev-dependencies]
pytest = "^7.1.2"
Expand Down
2 changes: 1 addition & 1 deletion vmngclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path
from typing import Final

LOGGING_CONF_DIR: Final[str] = str(Path(__file__).parents[0] / 'logging.conf')
LOGGING_CONF_DIR: Final[str] = str(Path(__file__).parents[0] / "logging.conf")

vmngclient_logger = logging.getLogger(__name__)

Expand Down
12 changes: 7 additions & 5 deletions vmngclient/api/admin_tech_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def get(self, device_id: str) -> List[DeviceAdminTech]:
Returns:
AdminTech object list for given device
"""
body = {'deviceIP': device_id}
response = self.session.post(url='/dataservice/device/tools/admintechlist', json=body)
body = {"deviceIP": device_id}
response = self.session.post(url="/dataservice/device/tools/admintechlist", json=body)
items = response.json()["data"]
return [create_dataclass(DeviceAdminTech, item) for item in items]

Expand All @@ -60,7 +60,7 @@ def get_all(self) -> List[AdminTech]:
Returns:
AdminTech objects list for all devices
"""
response = self.session.get('/dataservice/device/tools/admintechs')
response = self.session.get("/dataservice/device/tools/admintechs")
items = response.json()["data"]
return [create_dataclass(AdminTech, item) for item in items]

Expand Down Expand Up @@ -100,7 +100,9 @@ def generate(
)
try:
response = self.session.post(
url="/dataservice/device/tools/admintech", json=body, timeout=request_timeout
url="/dataservice/device/tools/admintech",
json=body,
timeout=request_timeout,
)
except HTTPError as http_error:
response = http_error.response
Expand All @@ -114,7 +116,7 @@ def generate(
raise GenerateAdminTechLogError(f"It is not possible to generate admintech log for {device_id}")
time.sleep(polling_interval)
polling_timer -= polling_interval
raise GenerateAdminTechLogError(f'It is not possible to generate admintech log for {device_id}')
raise GenerateAdminTechLogError(f"It is not possible to generate admintech log for {device_id}")

def _get_token_id(self, filename: str) -> str:
admin_techs = self.get_all()
Expand Down
39 changes: 31 additions & 8 deletions vmngclient/api/alarms_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,38 @@ class Viewed(Enum):

class AlarmsAPI:

URL = '/dataservice/alarms'
URL = "/dataservice/alarms"

def __init__(self, session: vManageSession):
self.session = session

def get_alarms(
self, hours: Optional[int] = None, level: Optional[str] = None, viewed: Optional[bool] = None
self,
hours: Optional[int] = None,
level: Optional[str] = None,
viewed: Optional[bool] = None,
) -> List[AlarmData]:
query: Dict[str, Any] = {"query": {"condition": "AND", "rules": []}}

if hours:
query["query"]["rules"].append(
{"value": [str(hours)], "field": "entry_time", "type": "date", "operator": "last_n_hours"}
{
"value": [str(hours)],
"field": "entry_time",
"type": "date",
"operator": "last_n_hours",
}
)

if level:
query["query"]["rules"].append({"value": [level], "field": "severity", "type": "string", "operator": "in"})
query["query"]["rules"].append(
{
"value": [level],
"field": "severity",
"type": "string",
"operator": "in",
}
)

if viewed is not None:
if viewed:
Expand All @@ -50,7 +65,12 @@ def get_alarms(
value = Viewed.no.value

query["query"]["rules"].append(
{"value": [value], "field": "acknowledged", "type": "bool", "operator": "equal"}
{
"value": [value],
"field": "acknowledged",
"type": "bool",
"operator": "equal",
}
)

alarms = self.session.post(url=AlarmsAPI.URL, json=query).json()["data"]
Expand Down Expand Up @@ -81,13 +101,16 @@ def mark_all_as_viewed(self) -> bool:
True if all alarms are viewed
"""

self.session.post(f'{AlarmsAPI.URL}/markallasviewed')
self.session.post(f"{AlarmsAPI.URL}/markallasviewed")
logger.info("Alarms mark as viewed.")

return not self.get_not_viewed_alarms()

def check_alarms(
self, expected: List[Dict[str, str]], timeout_seconds: int = 240, sleep_seconds: int = 5
self,
expected: List[Dict[str, str]],
timeout_seconds: int = 240,
sleep_seconds: int = 5,
) -> Dict[str, set]:
"""Checks if alarms have occurred.
Expand All @@ -112,7 +135,7 @@ def check_alarms(
logger.info(f"found alarms: {verification.found}")
logger.info(f"not-found alarms: {verification.not_found}")

return {'found': verification.found, 'not-found': verification.not_found}
return {"found": verification.found, "not-found": verification.not_found}


class AlarmVerification:
Expand Down
Loading

0 comments on commit 7215f32

Please sign in to comment.