Skip to content

Commit 812ae82

Browse files
rsjrnikokaojadoctrino
authored
[EXPERIMENTAL] Merge main (#1139)
# Description Please describe the change you have made. ## Bump - [ ] Patch - [ ] Minor - [x] Skip ## Changelog ### Added - My change. --------- Co-authored-by: Nikola Vasiljevic <35523348+nikokaoja@users.noreply.github.com> Co-authored-by: Anders Albert <60234212+doctrino@users.noreply.github.com>
1 parent deaff33 commit 812ae82

File tree

4 files changed

+162
-13
lines changed

4 files changed

+162
-13
lines changed

cognite/neat/_rules/models/entities/_wrapped.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,20 @@ def from_dms_filter(cls, filter: dm.Filter) -> "DMSFilter":
107107
(body := dumped.get(dm.filters.Equals._filter_name))
108108
and (value := body.get("value"))
109109
and isinstance(value, dict)
110+
and (space := value.get("space"))
111+
and (external_id := value.get("externalId"))
112+
):
113+
return NodeTypeFilter(inner=[DMSNodeEntity(space=space, externalId=external_id)])
114+
elif (
115+
(body := dumped.get(dm.filters.In._filter_name))
116+
and (values := body.get("values"))
117+
and all(
118+
[
119+
(True if isinstance(entry, dict) and "space" in entry and "externalId" in entry else False)
120+
for entry in values
121+
]
122+
)
110123
):
111-
space = value.get("space")
112-
external_id = value.get("externalId")
113-
if space is not None and external_id is not None:
114-
return NodeTypeFilter(inner=[DMSNodeEntity(space=space, externalId=external_id)])
115-
elif (body := dumped.get(dm.filters.In._filter_name)) and (values := body.get("values")):
116124
return NodeTypeFilter(
117125
inner=[
118126
DMSNodeEntity(space=entry["space"], externalId=entry["externalId"])

dev.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
CHANGELOG_ENTRY_FILE = REPO_ROOT / "last_changelog_entry.md"
2222
LAST_VERSION = REPO_ROOT / "last_version.txt"
2323
VERSION_PLACEHOLDER = "0.0.0"
24-
24+
VERSION_FILES = (
25+
REPO_ROOT / "pyproject.toml",
26+
REPO_ROOT / "cognite" / "neat" / "_version.py",
27+
)
2528

2629
dev_app = typer.Typer(
2730
add_completion=False,
@@ -34,10 +37,6 @@
3437

3538
@dev_app.command()
3639
def bump(verbose: bool = False) -> None:
37-
version_files = [
38-
REPO_ROOT / "pyproject.toml",
39-
REPO_ROOT / "cognite" / "neat" / "_version.py",
40-
]
4140
last_version_str = LAST_VERSION.read_text().strip().removeprefix("v")
4241
try:
4342
last_version = parse(last_version_str)
@@ -60,12 +59,12 @@ def bump(verbose: bool = False) -> None:
6059
else:
6160
raise typer.BadParameter("You must specify one of major, minor, patch, alpha, or beta.")
6261

63-
for file in version_files:
62+
for file in VERSION_FILES:
6463
file.write_text(file.read_text().replace(str(VERSION_PLACEHOLDER), str(new_version), 1))
6564
if verbose:
6665
typer.echo(f"Bumped version from {last_version} to {new_version} in {file}.")
6766

68-
typer.echo(f"Bumped version from {last_version} to {new_version} in {len(version_files)} files.")
67+
typer.echo(f"Bumped version from {last_version} to {new_version} in {len(VERSION_FILES)} files.")
6968

7069

7170
@dev_app.command("changelog")
@@ -95,6 +94,11 @@ def _read_last_commit_message() -> tuple[str, str | None]:
9594
return after_bump, None
9695

9796
bump_text, changelog_text = after_bump.split("## Changelog")
97+
98+
if "-----" in changelog_text:
99+
# Co-authors section
100+
changelog_text = changelog_text.split("-----")[0].strip()
101+
98102
return bump_text, changelog_text
99103

100104

tests/tests_unit/test_neat_package_metadata.py

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
from pathlib import Path
2+
from unittest.mock import MagicMock
23

4+
import pytest
5+
6+
import dev
37
from tests.config import ROOT
48

59

@@ -17,3 +21,111 @@ def test_no_spaces_in_sub_folders() -> None:
1721
raise ValueError(f"Subfolder with spaces found: {path}")
1822

1923
assert not name_by_location, f"Subfolders with spaces found: {name_by_location}"
24+
25+
26+
def get_release_process_test_cases():
27+
yield pytest.param(
28+
"""NEAT-899 Remove template. solution_model() (#1096)
29+
30+
# Description
31+
32+
Removing `template.solution_model()` as it is not robust to be public
33+
method
34+
35+
## Bump
36+
37+
- [X] Patch
38+
- [ ] Minor
39+
- [ ] Skip
40+
41+
## Changelog
42+
### Removed
43+
44+
- Removed `template.solution_model()` as it is not robust to be public
45+
method
46+
""",
47+
"0.119.8\n",
48+
"""
49+
### Removed
50+
51+
- Removed `template.solution_model()` as it is not robust to be public
52+
method""",
53+
"0.119.9",
54+
id="Patch bump",
55+
)
56+
57+
yield pytest.param(
58+
"""Enable dummy property per user defined concept (#1079)
59+
# Description
60+
61+
Enable adding dummy property for every user-defined concept when
62+
creating extension template.
63+
By default dummy property is formed as `idOfConceptGUID` , and it set to
64+
be string, none mandatory.
65+
Dummy properties help in avoiding to set filters in DMS.
66+
67+
## Bump
68+
69+
- [ ] Patch
70+
- [x] Minor
71+
- [ ] Skip
72+
73+
## Changelog
74+
### Added
75+
- Support for dummy properties in `template.extension()`
76+
77+
---------
78+
79+
Co-authored-by: Member <member@users.noreply.github.com>
80+
Co-authored-by: Member <member@cognite.com>""",
81+
"0.119.8\n",
82+
"""### Added
83+
- Support for dummy properties in `template.extension()`""",
84+
"0.120.0",
85+
id="Minor bump with co-authors",
86+
)
87+
88+
89+
class TestReleaseProcess:
90+
@pytest.mark.parametrize(
91+
"last_git_message, last_version, expected_changelog, expected_version", list(get_release_process_test_cases())
92+
)
93+
def test_bump_and_create_changelog_entry(
94+
self, last_git_message: str, last_version: str, expected_changelog: str, expected_version: str, monkeypatch
95+
) -> None:
96+
actual_changelog_entry: str | None = None
97+
actual_version: str | None = None
98+
last_git_message_file = MagicMock(spec=Path)
99+
last_git_message_file.read_text.return_value = last_git_message
100+
last_version_file = MagicMock(spec=Path)
101+
last_version_file.read_text.return_value = last_version
102+
103+
def mock_write_changelog(content, encoding=None):
104+
nonlocal actual_changelog_entry
105+
actual_changelog_entry = content
106+
107+
changelog_file = MagicMock(spec=Path)
108+
changelog_file.write_text = mock_write_changelog
109+
110+
version_file = MagicMock(spec=Path)
111+
version_file.read_text.return_value = dev.VERSION_PLACEHOLDER
112+
113+
def mock_write_version(content, **_):
114+
nonlocal actual_version
115+
actual_version = content
116+
117+
version_file.write_text = mock_write_version
118+
119+
monkeypatch.setattr(dev, "LAST_GIT_MESSAGE_FILE", last_git_message_file)
120+
monkeypatch.setattr(dev, "LAST_VERSION", last_version_file)
121+
monkeypatch.setattr(dev, "CHANGELOG_ENTRY_FILE", changelog_file)
122+
monkeypatch.setattr(dev, "VERSION_FILES", [version_file])
123+
124+
dev.bump()
125+
dev.create_changelog_entry()
126+
127+
assert actual_changelog_entry is not None, "Changelog entry was not created"
128+
assert actual_changelog_entry == expected_changelog
129+
130+
assert actual_version is not None, "Version was not updated"
131+
assert actual_version == expected_version

tests/tests_unit/test_rules/test_models/test_wrapped_entities.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ def test_load(self, cls_: type[WrappedEntity], raw: Any, expected: WrappedEntity
106106
(
107107
dm.filters.In(
108108
["node", "type"],
109-
[{"space": "space", "externalId": "node1"}, {"space": "space", "externalId": "node2"}],
109+
[
110+
{"space": "space", "externalId": "node1"},
111+
{"space": "space", "externalId": "node2"},
112+
],
110113
),
111114
NodeTypeFilter(
112115
inner=[
@@ -115,6 +118,28 @@ def test_load(self, cls_: type[WrappedEntity], raw: Any, expected: WrappedEntity
115118
]
116119
),
117120
),
121+
(
122+
dm.filters.In(
123+
property=["cdf_cdm", "CogniteFile", "mimeType"],
124+
values=[
125+
"application/pdf",
126+
"application/msword",
127+
"image/jpeg",
128+
"image/tiff",
129+
"image/png",
130+
"application/vnd.ms-excel",
131+
"application/vnd.ms-excel.sheet.macroEnabled.12",
132+
],
133+
),
134+
RawFilter(
135+
filter=(
136+
'rawFilter({"in": {"property": ["cdf_cdm", "CogniteFile", "mimeType"], '
137+
'"values": ["application/pdf", "application/msword", "image/jpeg", '
138+
'"image/tiff", "image/png", "application/vnd.ms-excel", '
139+
'"application/vnd.ms-excel.sheet.macroEnabled.12"]}})'
140+
)
141+
),
142+
),
118143
pytest.param(
119144
dm.filters.Equals(["govern-space", "Property", "type"], "Input"),
120145
RawFilter(filter='{"equals": {"property": ["govern-space", "Property", "type"], "value": "Input"}}'),

0 commit comments

Comments
 (0)