File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -125,7 +125,7 @@ def __init__(
125125
126126 if self .source_type == URL_SOURCE :
127127 if check_exports is True :
128- raise ValueError ("Cannot check exports for source type {source_type!r}" )
128+ raise ValueError (f "Cannot check exports of source type { source_type !r} " )
129129 elif source_file is not None :
130130 raise ValueError (f"File given, but source type is { source_type !r} " )
131131 else :
Original file line number Diff line number Diff line change @@ -30,6 +30,14 @@ def test_add_web_module_source_must_exist(tmp_path):
3030 add_web_module ("test" , tmp_path / "file-does-not-exist.js" )
3131
3232
33+ def test_cannot_add_web_module_if_already_exists (tmp_path ):
34+ temp_file = tmp_path / "temp.js"
35+ temp_file .write_text ("console.log('hello!')" ) # this won't get run
36+ add_web_module ("test" , temp_file )
37+ with pytest .raises (ValueError , match = "already exists" ):
38+ add_web_module ("test" , temp_file )
39+
40+
3341def test_web_module_path_must_exist ():
3442 with pytest .raises (ValueError , match = "does not exist at path" ):
3543 web_module_path ("this-does-not-exist" , must_exist = True )
Original file line number Diff line number Diff line change @@ -116,3 +116,26 @@ def test_module_must_export_mount_if_exports_mount_is_set():
116116 source_file = JS_FIXTURES / "component-without-mount.js" ,
117117 exports_mount = True ,
118118 )
119+
120+
121+ def test_cannot_have_source_file_for_url_source_type ():
122+ with pytest .raises (ValueError , match = "File given, but source type is 'URL'" ):
123+ idom .Module ("test" , source_file = "something.js" , source_type = URL_SOURCE )
124+
125+
126+ def test_cannot_check_exports_for_url_source_type ():
127+ with pytest .raises (ValueError , match = "Can't check exports for source type 'URL'" ):
128+ idom .Module ("test" , check_exports = True , source_type = URL_SOURCE )
129+
130+
131+ def test_invalid_source_type ():
132+ with pytest .raises (ValueError , match = "Invalid source type" ):
133+ idom .Module ("test" , source_type = "TYPE_DOES_NOT_EXIST" )
134+
135+
136+ def test_attribute_error_if_lowercase_name_doesn_not_exist ():
137+ mod = idom .Module ("test" , source_type = URL_SOURCE )
138+ with pytest .raises (AttributeError , match = "this_attribute_does_not_exist" ):
139+ # This attribute would otherwise be considered to
140+ # be the name of a component the module exports.
141+ mod .this_attribute_does_not_exist
You can’t perform that action at this time.
0 commit comments