@@ -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