Skip to content

Commit eb51f58

Browse files
committed
address comments
1 parent 4f61fa1 commit eb51f58

3 files changed

Lines changed: 71 additions & 9 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ After modifying the `entrypoint.py` as needed, using any dependencies you add in
7979
```zsh
8080
cd my_package
8181
datacustomcode scan ./payload/entrypoint.py
82-
datacustomcode zip --path ./payload
8382
datacustomcode deploy --path ./payload --name my_custom_script --cpu-size CPU_L
8483
```
8584

src/datacustomcode/scan.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,17 @@ def dc_config_json_from_file(file_path: str) -> dict[str, Any]:
249249
if not dataspace_value or (
250250
isinstance(dataspace_value, str) and dataspace_value.strip() == ""
251251
):
252-
logger.error(
253-
f"dataspace in {config_json_path} is empty or None."
254-
f"Updating config file to use dataspace 'default'."
252+
logger.warning(
253+
f"dataspace in {config_json_path} is empty or None. "
254+
f"Updating config file to use dataspace 'default'. "
255255
)
256256
config["dataspace"] = "default"
257257
else:
258258
config["dataspace"] = dataspace_value
259259
else:
260260
raise ValueError(
261261
f"dataspace must be defined in {config_json_path}. "
262-
f"Please add a 'dataspace' field to the config.json file."
262+
f"Please add a 'dataspace' field to the config.json file. "
263263
)
264264
except json.JSONDecodeError as e:
265265
raise ValueError(

tests/test_scan.py

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,10 @@ def test_preserves_existing_dataspace(self):
423423
},
424424
},
425425
)
426-
def test_rejects_empty_dataspace(self):
427-
"""Test that empty dataspace value uses default and logs error."""
426+
def test_uses_default_for_empty_dataspace(self, caplog):
427+
"""Test that empty dataspace value uses default and logs warning."""
428428
import json
429+
import logging
429430

430431
content = textwrap.dedent(
431432
"""
@@ -455,10 +456,20 @@ def test_rejects_empty_dataspace(self):
455456
json.dump(existing_config, f)
456457

457458
# Should use "default" for empty dataspace (not raise error)
458-
result = dc_config_json_from_file(temp_path)
459+
with caplog.at_level(logging.WARNING):
460+
result = dc_config_json_from_file(temp_path)
461+
459462
assert result["dataspace"] == "default"
460463
assert result["permissions"]["read"]["dlo"] == ["input_dlo"]
461464
assert result["permissions"]["write"]["dlo"] == ["output_dlo"]
465+
466+
# Verify that a warning was logged
467+
assert len(caplog.records) > 0
468+
assert any(
469+
"dataspace" in record.message.lower()
470+
and "empty" in record.message.lower()
471+
for record in caplog.records
472+
)
462473
finally:
463474
os.remove(temp_path)
464475
if os.path.exists(config_path):
@@ -476,7 +487,7 @@ def test_rejects_empty_dataspace(self):
476487
},
477488
},
478489
)
479-
def test_rejects_missing_dataspace(self):
490+
def test_uses_default_dataspace_when_no_config(self):
480491
"""Test missing config.json uses default dataspace."""
481492
content = textwrap.dedent(
482493
"""
@@ -498,6 +509,58 @@ def test_rejects_missing_dataspace(self):
498509
finally:
499510
os.remove(temp_path)
500511

512+
@patch(
513+
"datacustomcode.scan.DATA_TRANSFORM_CONFIG_TEMPLATE",
514+
{
515+
"sdkVersion": "1.2.3",
516+
"entryPoint": "",
517+
"dataspace": "",
518+
"permissions": {
519+
"read": {},
520+
"write": {},
521+
},
522+
},
523+
)
524+
def test_rejects_missing_dataspace(self):
525+
"""Test that config.json missing dataspace field raises ValueError."""
526+
import json
527+
528+
content = textwrap.dedent(
529+
"""
530+
from datacustomcode.client import Client
531+
532+
client = Client()
533+
df = client.read_dlo("input_dlo")
534+
client.write_to_dlo("output_dlo", df, "overwrite")
535+
"""
536+
)
537+
temp_path = create_test_script(content)
538+
file_dir = os.path.dirname(temp_path)
539+
config_path = os.path.join(file_dir, "config.json")
540+
541+
try:
542+
# Create an existing config.json without dataspace field
543+
existing_config = {
544+
"sdkVersion": "1.0.0",
545+
"entryPoint": "test.py",
546+
"permissions": {
547+
"read": {"dlo": ["old_dlo"]},
548+
"write": {"dlo": ["old_output"]},
549+
},
550+
}
551+
with open(config_path, "w") as f:
552+
json.dump(existing_config, f)
553+
554+
# Should raise ValueError when dataspace field is missing
555+
with pytest.raises(
556+
ValueError, match="dataspace must be defined in.*config.json"
557+
):
558+
dc_config_json_from_file(temp_path)
559+
finally:
560+
os.remove(temp_path)
561+
if os.path.exists(config_path):
562+
os.remove(config_path)
563+
501564
def test_raises_error_on_invalid_json(self):
502565
"""Test that invalid JSON in config.json raises an error."""
503566

0 commit comments

Comments
 (0)