Skip to content

Commit c9ba0be

Browse files
committed
Delete config convert tests
1 parent 59de35b commit c9ba0be

23 files changed

+2
-627
lines changed

crates/pcb-zen-core/tests/input.rs

Lines changed: 2 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -373,61 +373,6 @@ snapshot_eval!(interface_mixed_templates_and_types, {
373373
"#
374374
});
375375

376-
snapshot_eval!(config_with_convert_function, {
377-
"Module.zen" => r#"
378-
# Define a record type for units
379-
UnitType = record(
380-
value = field(float),
381-
unit = field(str),
382-
)
383-
384-
# Define a converter function that parses strings like "5V" into the record
385-
def parse_unit(s):
386-
if type(s) == "string":
387-
# Simple parser: extract number and unit
388-
import_value = ""
389-
import_unit = ""
390-
for c in s.elems():
391-
if c.isdigit() or c == ".":
392-
import_value += c
393-
else:
394-
import_unit += c
395-
396-
if import_value and import_unit:
397-
return UnitType(value = float(import_value), unit = import_unit)
398-
return s
399-
400-
# Test 1: config with converter should accept string and convert to record
401-
# Provide a default since records require defaults
402-
voltage = config("voltage", UnitType, default = UnitType(value = 0.0, unit = "V"), convert = parse_unit)
403-
404-
# Test 2: config with converter and default value that needs conversion
405-
# The default string should be converted when no value is provided
406-
current = config("current", UnitType, default = "2.5A", convert = parse_unit)
407-
408-
# Test 3: optional config with converter
409-
optional_power = config("power", UnitType, convert = parse_unit, optional = True)
410-
411-
# Add properties to verify the values
412-
add_property("voltage_value", voltage.value)
413-
add_property("voltage_unit", voltage.unit)
414-
add_property("current_value", current.value)
415-
add_property("current_unit", current.unit)
416-
add_property("optional_power_is_none", optional_power == None)
417-
"#,
418-
"top.zen" => r#"
419-
Mod = Module("Module.zen")
420-
421-
# Provide string input that should be converted
422-
Mod(
423-
name = "test",
424-
voltage = "5V",
425-
# current uses default "2.5A" which should be converted
426-
# power is optional and not provided
427-
)
428-
"#
429-
});
430-
431376
snapshot_eval!(config_without_convert_fails_type_check, {
432377
"Module.zen" => r#"
433378
UnitType = record(
@@ -450,122 +395,6 @@ snapshot_eval!(config_without_convert_fails_type_check, {
450395
"#
451396
});
452397

453-
snapshot_eval!(config_convert_with_default, {
454-
"Module.zen" => r#"
455-
def int_to_string(x):
456-
# Convert int to string with prefix
457-
return "value_" + str(x)
458-
459-
# Config with default that needs conversion - int to string
460-
name = config("name", str, default = 42, convert = int_to_string)
461-
462-
# Verify the default was converted by adding it as a property
463-
add_property("name_value", name)
464-
"#,
465-
"top.zen" => r#"
466-
Mod = Module("Module.zen")
467-
468-
# Don't provide input, so default is used and converted
469-
Mod(name = "test")
470-
"#
471-
});
472-
473-
snapshot_eval!(config_convert_preserves_correct_types, {
474-
"Module.zen" => r#"
475-
UnitType = record(
476-
value = field(float),
477-
unit = field(str),
478-
)
479-
480-
converter_called = [False] # Use list to allow mutation in nested function
481-
482-
def tracking_converter(x):
483-
# This converter tracks if it was called
484-
converter_called[0] = True
485-
return x
486-
487-
# If we pass a proper record, the converter should not be invoked
488-
# Provide a default since records require defaults
489-
voltage = config("voltage", UnitType, default = UnitType(value = 0.0, unit = "V"), convert = tracking_converter)
490-
491-
# Add properties to verify behavior
492-
add_property("converter_called", converter_called[0])
493-
add_property("voltage_value", voltage.value)
494-
add_property("voltage_unit", voltage.unit)
495-
"#,
496-
"top.zen" => r#"
497-
MyModule = Module("./Module.zen")
498-
499-
# Create a proper record value
500-
unit_value = MyModule.UnitType(value = 5.0, unit = "V")
501-
502-
# Pass the correct type - converter should not be called
503-
MyModule(
504-
name = "test",
505-
voltage = unit_value,
506-
)
507-
"#
508-
});
509-
510-
snapshot_eval!(config_convert_chain, {
511-
"Module.zen" => r#"
512-
def parse_number(s):
513-
if type(s) == "string":
514-
return float(s)
515-
return s
516-
517-
def multiply_by_two(x):
518-
return x * 2
519-
520-
def composed_converter(s):
521-
return multiply_by_two(parse_number(s))
522-
523-
# String "5" -> 5.0 -> 10.0
524-
value = config("value", float, convert = composed_converter)
525-
526-
# Add property to verify the conversion
527-
add_property("converted_value", value)
528-
"#,
529-
"top.zen" => r#"
530-
Mod = Module("Module.zen")
531-
532-
# Provide string that will be converted through the chain
533-
Mod(
534-
name = "test",
535-
value = "5",
536-
)
537-
"#
538-
});
539-
540-
snapshot_eval!(config_convert_with_enum, {
541-
"Module.zen" => r#"
542-
# Define an enum type
543-
Direction = enum("NORTH", "SOUTH", "EAST", "WEST")
544-
545-
def direction_converter(s):
546-
# Convert string to enum variant
547-
if type(s) == "string":
548-
# Call the enum factory with the uppercase string
549-
return Direction(s.upper())
550-
return s
551-
552-
# Config that converts string to enum
553-
heading = config("heading", Direction, convert = direction_converter)
554-
555-
# Add property to verify conversion
556-
add_property("heading_is_north", heading == Direction("NORTH"))
557-
"#,
558-
"top.zen" => r#"
559-
Mod = Module("Module.zen")
560-
561-
# Provide lowercase string that should be converted to enum
562-
Mod(
563-
name = "test",
564-
heading = "north",
565-
)
566-
"#
567-
});
568-
569398
snapshot_eval!(io_config_with_help_text, {
570399
"Module.zen" => r#"
571400
# Test io() and config() with help parameter
@@ -581,13 +410,7 @@ snapshot_eval!(io_config_with_help_text, {
581410
# Optional config with help
582411
debug_mode = config("debug_mode", bool, optional = True, help = "Enable debug logging")
583412
584-
# Config with converter and help
585-
def parse_voltage(s):
586-
if type(s) == "string" and s.endswith("V"):
587-
return float(s[:-1])
588-
return s
589-
590-
voltage = config("voltage", float, default = 3.3, convert = parse_voltage, help = "Operating voltage in volts")
413+
voltage = config("voltage", float, default = 3.3, help = "Operating voltage in volts")
591414
592415
# Add a component to make the module valid
593416
Component(
@@ -606,7 +429,7 @@ snapshot_eval!(io_config_with_help_text, {
606429
power = Net("VCC"),
607430
baud_rate = 115200,
608431
device_name = "TestDevice",
609-
voltage = "5V", # This will be converted to 5.0
432+
voltage = 5.0,
610433
)
611434
"#
612435
});

crates/pcb-zen-core/tests/snapshots/component__component_has_attr_dynamic.snap

Lines changed: 0 additions & 67 deletions
This file was deleted.

crates/pcb-zen-core/tests/snapshots/component__component_mutation_dnp.snap

Lines changed: 0 additions & 46 deletions
This file was deleted.

crates/pcb-zen-core/tests/snapshots/component__component_mutation_manufacturer.snap

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)