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

attempt for doing camel case check in all classes #1385

Merged
merged 7 commits into from
Oct 5, 2023
Merged
Changes from all 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
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__)