@@ -8,15 +8,14 @@ def test_data_to_device():
88 device = torch .device ("cpu" )
99 t1 = torch .randn (2 , 2 )
1010 t2 = torch .randn (3 , 3 )
11- data = [t1 , (t2 , "not_a_tensor" )]
11+ data = [t1 , (t2 ,)]
1212
1313 # Execute
1414 moved_data = data_to_device (data , device )
1515
1616 # Verify
1717 assert torch .equal (moved_data [0 ], t1 .to (device ))
1818 assert torch .equal (moved_data [1 ][0 ], t2 .to (device ))
19- assert moved_data [1 ][1 ] == "not_a_tensor"
2019 assert isinstance (moved_data , list )
2120 assert isinstance (moved_data [1 ], tuple )
2221
@@ -25,13 +24,13 @@ def test_get_data_shape():
2524 # Setup
2625 t1 = torch .randn (2 , 3 )
2726 t2 = torch .randn (4 , 5 , 6 )
28- data = (t1 , [t2 , "label" ])
27+ data = (t1 , [t2 ])
2928
3029 # Execute
3130 shapes = get_data_shape (data )
3231
3332 # Verify
34- assert shapes == ((2 , 3 ), [(4 , 5 , 6 ), "label" ])
33+ assert shapes == ((2 , 3 ), [(4 , 5 , 6 )])
3534 assert isinstance (shapes , tuple )
3635 assert isinstance (shapes [1 ], list )
3736
@@ -40,22 +39,38 @@ def test_unsqueeze_data():
4039 # Setup
4140 t1 = torch .randn (2 , 2 )
4241 t2 = torch .randn (3 , 3 )
43- data = [t1 , (t2 , "text" )]
42+ data = [t1 , (t2 ,)]
4443
4544 # Execute
4645 unsqueezed = unsqueeze_data (data , dim = 0 )
4746
4847 # Verify
4948 assert unsqueezed [0 ].shape == (1 , 2 , 2 )
5049 assert unsqueezed [1 ][0 ].shape == (1 , 3 , 3 )
51- assert unsqueezed [1 ][1 ] == "text"
5250 assert isinstance (unsqueezed , list )
5351 assert isinstance (unsqueezed [1 ], tuple )
5452
5553
56- def test_torch_non_tensor_passthrough ():
57- # Ensure non-tensors are passed through correctly
54+ def test_torch_raises_type_error ():
55+ # Ensure non-tensors raise TypeError
5856 data = "string"
59- assert data_to_device (data , torch .device ("cpu" )) == "string"
60- assert get_data_shape (data ) == "string"
61- assert unsqueeze_data (data ) == "string"
57+ device = torch .device ("cpu" )
58+
59+ with pytest .raises (TypeError , match = "expected torch.Tensor" ):
60+ data_to_device (data , device )
61+
62+ with pytest .raises (TypeError , match = "expected torch.Tensor" ):
63+ get_data_shape (data )
64+
65+ with pytest .raises (TypeError , match = "expected torch.Tensor" ):
66+ unsqueeze_data (data )
67+
68+ def test_torch_raises_type_error_nested ():
69+ # Test nested invalid types
70+ data = [torch .randn (2 ), "invalid" ]
71+
72+ with pytest .raises (TypeError , match = "expected torch.Tensor" ):
73+ data_to_device (data , torch .device ("cpu" ))
74+
75+ with pytest .raises (TypeError , match = "expected torch.Tensor" ):
76+ get_data_shape (data )
0 commit comments