From 1998cdab623e7d0c26f4fbf41f4af3867566aac1 Mon Sep 17 00:00:00 2001 From: Alan Pinkert Date: Fri, 19 Apr 2024 09:56:43 -0400 Subject: [PATCH 1/2] cleanup a variety of typing and duplicate errors --- ocsf_validator/errors.py | 4 ++-- ocsf_validator/matchers.py | 5 +++-- ocsf_validator/processor.py | 4 ++-- ocsf_validator/runner.py | 6 +++--- ocsf_validator/type_mapping.py | 2 +- ocsf_validator/types.py | 1 - ocsf_validator/validators.py | 2 +- tests/test_dependencies.py | 2 +- tests/test_validators.py | 2 +- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ocsf_validator/errors.py b/ocsf_validator/errors.py index 7685a94..f305dfd 100644 --- a/ocsf_validator/errors.py +++ b/ocsf_validator/errors.py @@ -196,9 +196,9 @@ def __init__( self.file = file self.include = include if isinstance(t, str): - self.cls = t + self.cls: str = t else: - self.cls: str = t.__name__ + self.cls = t.__name__ self.directive = directive super().__init__( f"`{directive}` type mismatch in {file}: expected type `{self.cls}` for {include}" diff --git a/ocsf_validator/matchers.py b/ocsf_validator/matchers.py index 28f261d..bf9f76d 100644 --- a/ocsf_validator/matchers.py +++ b/ocsf_validator/matchers.py @@ -1,5 +1,6 @@ +from __future__ import annotations + import re -from abc import ABC from pathlib import Path from typing import Optional @@ -11,7 +12,7 @@ def match(self, value: str) -> bool: raise NotImplementedError() @staticmethod - def make(pattern): + def make(pattern) -> Matcher: if isinstance(pattern, Matcher): return pattern else: diff --git a/ocsf_validator/processor.py b/ocsf_validator/processor.py index 800e8ae..f7e5d67 100644 --- a/ocsf_validator/processor.py +++ b/ocsf_validator/processor.py @@ -413,10 +413,10 @@ def apply(self, path: str) -> None: class Dependencies: """A friendly list of dependencies.""" - def __init__(self): + def __init__(self) -> None: self._dependencies: dict[str, list[tuple[str, str]]] = {} - def add(self, child: str, parent: str, label: str = ""): + def add(self, child: str, parent: str, label: str = "") -> None: if child not in self._dependencies: self._dependencies[child] = [] self._dependencies[child].append((parent, label)) diff --git a/ocsf_validator/runner.py b/ocsf_validator/runner.py index 024470e..246c527 100644 --- a/ocsf_validator/runner.py +++ b/ocsf_validator/runner.py @@ -6,7 +6,7 @@ from dataclasses import dataclass from enum import IntEnum from pathlib import Path -from typing import Callable +from typing import Callable, Optional from termcolor import colored @@ -42,7 +42,7 @@ class ValidatorOptions: base_path: str = "." """The base path of the schema.""" - metaschema_path: str = None + metaschema_path: Optional[str] = None """The path to the schema's metaschema.""" extensions: bool = True @@ -204,7 +204,7 @@ def txt_label(self, severity: int): case _: return self.txt_emphasize("???") - def validate(self): + def validate(self) -> None: exit_code = 0 messages: dict[str, dict[int, set[str]]] = {} collector = errors.Collector(throw=False) diff --git a/ocsf_validator/type_mapping.py b/ocsf_validator/type_mapping.py index f80c734..9d10769 100644 --- a/ocsf_validator/type_mapping.py +++ b/ocsf_validator/type_mapping.py @@ -5,7 +5,7 @@ from ocsf_validator.reader import Reader from ocsf_validator.types import * -MATCHERS = [ +MATCHERS: list = [ VersionMatcher(), DictionaryMatcher(), CategoriesMatcher(), diff --git a/ocsf_validator/types.py b/ocsf_validator/types.py index 20598d4..227e071 100644 --- a/ocsf_validator/types.py +++ b/ocsf_validator/types.py @@ -112,7 +112,6 @@ class OcsfInclude(TypedDict): class OcsfProfile(TypedDict): - caption: str caption: str description: str meta: str diff --git a/ocsf_validator/validators.py b/ocsf_validator/validators.py index 511513b..983e73f 100644 --- a/ocsf_validator/validators.py +++ b/ocsf_validator/validators.py @@ -268,7 +268,7 @@ def validate(reader: Reader, file: str): def _default_get_registry(reader: Reader, base_uri: str) -> referencing.Registry: - registry = referencing.Registry() + registry: referencing.Registry = referencing.Registry() for schema_file_path in reader.metaschema_path.glob("*.schema.json"): with open(schema_file_path, "r") as file: schema = json.load(file) diff --git a/tests/test_dependencies.py b/tests/test_dependencies.py index c9922c8..d8ff249 100644 --- a/tests/test_dependencies.py +++ b/tests/test_dependencies.py @@ -123,7 +123,7 @@ def test_extends(): assert "thing" in r["/events/network/http_activity.json"]["attributes"] -def test_profiles(): +def test_profiles_basic(): prof = event("profile1", ["thing"]) httpa = event("http_activity") httpa["profiles"] = "profile1" diff --git a/tests/test_validators.py b/tests/test_validators.py index 0538ca9..6c68da9 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -363,7 +363,7 @@ def test_validate_metaschemas(): } def _get_registry(reader, base_uri) -> referencing.Registry: - registry = referencing.Registry() + registry: referencing.Registry = referencing.Registry() for schema in METASCHEMA_MATCHERS.keys(): resource = referencing.Resource.from_contents(object_json_schema) registry = registry.with_resource(base_uri + schema, resource=resource) From 821d8c43b33a7fe8ad4e317bc98c537ea3e5d352 Mon Sep 17 00:00:00 2001 From: Alan Pinkert Date: Wed, 24 Apr 2024 15:25:01 -0400 Subject: [PATCH 2/2] bump version number --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c685849..1087e20 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ocsf-validator" -version = "0.1.7" +version = "0.1.8" description = "OCSF Schema Validation" authors = [ "Jeremy Fisher ",