Skip to content

Commit

Permalink
attempt for doing camel case check in all classes (#1385)
Browse files Browse the repository at this point in the history
Co-authored-by: Hayden Hohns <[email protected]>
  • Loading branch information
HaydenCognite and HaydenCognite authored Oct 5, 2023
1 parent ae47d95 commit c37e4f7
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions tests/tests_unit/test_meta.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import inspect
from pathlib import Path

import pytest

from cognite.client.data_classes._base import CogniteResource, CogniteResourceList
from tests.utils import all_subclasses

ALL_FILEPATHS = Path("cognite/client/").rglob("*.py")


def test_assert_no_root_init_file():
# We have an implicit namespace package under the namespace package directory: 'cognite'.
Expand All @@ -19,10 +27,18 @@ def keep(path):
]
return all(skip not in str(path.as_posix()) for skip in skip_list)

all_filepaths = Path("cognite/client/").glob("**/*.py")
err_msg = "File: '{}' is missing 'from __future__ import annotations' at line=0"

for filepath in filter(keep, all_filepaths):
for filepath in filter(keep, ALL_FILEPATHS):
with filepath.open("r") as file:
# We just read the first line from each file:
assert file.readline() == "from __future__ import annotations\n", err_msg.format(filepath)


@pytest.mark.parametrize("cls", [CogniteResource, CogniteResourceList])
def test_ensure_all_to_pandas_methods_use_snake_case(cls):
err_msg = "Class: '{}' for method to_pandas does not default camel_case parameter to False."
for sub_cls in all_subclasses(cls):
if not (cls_method := getattr(sub_cls, "to_pandas", False)):
continue
if param := inspect.signature(cls_method).parameters.get("camel_case"):
assert param.default is False, err_msg.format(sub_cls.__name__)

0 comments on commit c37e4f7

Please sign in to comment.