Skip to content

Commit 952e999

Browse files
authored
Reduce duplication in unit test names (#532)
* Shorten names for model unit tests * Shorten names for tensor unit tests
1 parent 9361566 commit 952e999

12 files changed

Lines changed: 141 additions & 141 deletions

test/unit/model/unittest_model_constructors_destructors.pf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ contains
2424
! Unit test for the association of model pointers before and after loading
2525
! a TorchScript model and after deletion.
2626
@test
27-
subroutine test_torch_model_pointers()
27+
subroutine test_pointers()
2828
type(torch_model) :: model
2929

3030
! Check the model pointer is not associated
@@ -38,6 +38,6 @@ contains
3838
call torch_model_delete(model)
3939
@assertFalse(c_associated(model%p))
4040

41-
end subroutine test_torch_model_pointers
41+
end subroutine test_pointers
4242

4343
end module unittest_model_constructors_destructors

test/unit/model/unittest_model_forward.pf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ contains
8181

8282
! Unit test for checking values are propagated correctly through the test model
8383
@test(testparameters={get_parameters_short()})
84-
subroutine test_torch_model_forward_value(this)
84+
subroutine test_forward_value(this)
8585
use ftorch_tensor, only: torch_tensor_from_array
8686

8787
implicit none
@@ -104,13 +104,13 @@ contains
104104
call torch_model_forward(model, input_tensors, output_tensors)
105105

106106
expected = [0.0_wp, 2.0_wp, 4.0_wp, 6.0_wp, 8.0_wp]
107-
@assertTrue(assert_allclose(output_array, expected, test_name="test_torch_model_forward_value"))
107+
@assertTrue(assert_allclose(output_array, expected, test_name="test_forward_value"))
108108

109-
end subroutine test_torch_model_forward_value
109+
end subroutine test_forward_value
110110

111111
! Unit test for checking that requires_grad is correctly propagated through the test model
112112
@test(testparameters={get_parameters_requires_grad()})
113-
subroutine test_tensor_requires_grad(this)
113+
subroutine test_output_requires_grad(this)
114114
use ftorch_tensor, only: torch_tensor_ones, torch_tensor_empty
115115

116116
implicit none
@@ -135,6 +135,6 @@ contains
135135
! Check that the output tensor has the correct requires_grad property
136136
@assertEqual(this%param%requires_grad, output_tensors(1)%requires_grad())
137137

138-
end subroutine test_tensor_requires_grad
138+
end subroutine test_output_requires_grad
139139

140140
end module unittest_model_forward

test/unit/model/unittest_model_interrogation.pf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ contains
6969

7070
! Unit test for printing the parameters associated with a TorchScript model
7171
@test(testparameters={get_parameters_short()})
72-
subroutine test_torch_model_print_parameters(this)
72+
subroutine test_print_parameters(this)
7373
use ftorch_model, only: torch_model_print_parameters
7474
class(TestCaseType), intent(inout) :: this
7575
type(torch_model) :: model
@@ -80,11 +80,11 @@ contains
8080
! Check that printing the model parameters doesn't raise an error
8181
call torch_model_print_parameters(model)
8282

83-
end subroutine test_torch_model_print_parameters
83+
end subroutine test_print_parameters
8484

8585
! Unit test for checking the default of whether a Torch Model is in training mode
8686
@test(testparameters={get_parameters_short()})
87-
subroutine test_torch_model_is_training_default(this)
87+
subroutine test_is_training_default(this)
8888
class(TestCaseType), intent(inout) :: this
8989
type(torch_model) :: model
9090

@@ -94,11 +94,11 @@ contains
9494
! Check that printing the model parameters doesn't raise an error
9595
@assertFalse(model%is_training())
9696

97-
end subroutine test_torch_model_is_training_default
97+
end subroutine test_is_training_default
9898

9999
! Unit test for checking whether a Torch Model is in training mode
100100
@test(testparameters={get_parameters_is_training()})
101-
subroutine test_torch_model_is_training(this)
101+
subroutine test_is_training(this)
102102
class(TestCaseType), intent(inout) :: this
103103
type(torch_model) :: model
104104

@@ -108,6 +108,6 @@ contains
108108
! Check that printing the model parameters doesn't raise an error
109109
@assertEqual(this%param%is_training, model%is_training())
110110

111-
end subroutine test_torch_model_is_training
111+
end subroutine test_is_training
112112

113113
end module unittest_model_interrogation

test/unit/tensor/unittest_tensor_autograd.pf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ contains
146146
end function toString
147147

148148
@test(testParameters={get_parameters_short()})
149-
subroutine test_torch_tensor_zero_grad(this)
149+
subroutine test_zero_grad(this)
150150

151151
implicit none
152152

@@ -174,19 +174,19 @@ contains
174174
call torch_tensor_backward(Q)
175175
call torch_tensor_get_gradient(dQda, a)
176176
expected(:,:) = 1.0
177-
@assertTrue(allclose(out_data, expected, test_name="test_torch_tensor_zero_grad1"))
177+
@assertTrue(allclose(out_data, expected, test_name="test_zero_grad1"))
178178

179179
! Call torch_tensor_zero_grad and check the gradient is indeed reset to zero. Note that we need
180180
! to call torch_tensor_get_gradient again after zeroing out these values.
181181
call a%zero_grad()
182182
call torch_tensor_get_gradient(dQda, a)
183183
expected(:,:) = 0.0
184-
@assertTrue(allclose(out_data, expected, test_name="test_torch_tensor_zero_grad2"))
184+
@assertTrue(allclose(out_data, expected, test_name="test_zero_grad2"))
185185

186-
end subroutine test_torch_tensor_zero_grad
186+
end subroutine test_zero_grad
187187

188188
@test(testParameters={get_parameters_short()})
189-
subroutine test_torch_tensor_retain_graph(this)
189+
subroutine test_retain_graph(this)
190190

191191
implicit none
192192

@@ -214,16 +214,16 @@ contains
214214
call torch_tensor_backward(Q)
215215
call torch_tensor_get_gradient(dQda, a)
216216
expected(:,:) = 1.0
217-
@assertTrue(allclose(out_data, expected, test_name="test_torch_tensor_retain_graph1"))
217+
@assertTrue(allclose(out_data, expected, test_name="test_retain_graph1"))
218218

219219
! Zero the gradient and then call back-propagation again and check the computed gradient still
220220
! takes the expected value
221221
call a%zero_grad()
222222
call torch_tensor_backward(Q, retain_graph=.true.)
223223
call torch_tensor_get_gradient(dQda, a)
224-
@assertTrue(allclose(out_data, expected, test_name="test_torch_tensor_retain_graph2"))
224+
@assertTrue(allclose(out_data, expected, test_name="test_retain_graph2"))
225225

226-
end subroutine test_torch_tensor_retain_graph
226+
end subroutine test_retain_graph
227227

228228
! ============================================================================
229229
! --- Unit tests for the requires_grad property

test/unit/tensor/unittest_tensor_constructors_destructors.pf

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ contains
9595

9696
! Unit test for the torch_tensor_empty subroutine
9797
@test(testparameters={get_parameters_requires_grad()})
98-
subroutine test_torch_tensor_empty(this)
98+
subroutine test_empty(this)
9999
use ftorch_tensor, only: torch_tensor_empty
100100

101101
implicit none
@@ -120,11 +120,11 @@ contains
120120
@assertEqual(expected_stride, tensor % get_stride())
121121
@assertEqual(tensor_shape, tensor % get_shape())
122122

123-
end subroutine test_torch_tensor_empty
123+
end subroutine test_empty
124124

125125
! Unit test for the torch_tensor_zeros subroutine
126126
@test(testParameters={get_parameters_requires_grad()})
127-
subroutine test_torch_tensor_zeros(this)
127+
subroutine test_zeros(this)
128128
use ftorch_tensor, only: torch_tensor_zeros
129129

130130
implicit none
@@ -160,13 +160,13 @@ contains
160160

161161
! Check that the tensor values are all zero
162162
expected(:,:) = 0.0
163-
@assertTrue(allclose(out_data, expected, test_name="test_torch_tensor_zeros"))
163+
@assertTrue(allclose(out_data, expected, test_name="test_zeros"))
164164

165-
end subroutine test_torch_tensor_zeros
165+
end subroutine test_zeros
166166

167167
! Unit test for the torch_tensor_ones subroutine
168168
@test(testParameters={get_parameters_requires_grad()})
169-
subroutine test_torch_tensor_ones(this)
169+
subroutine test_ones(this)
170170
use ftorch_tensor, only: torch_tensor_ones
171171

172172
implicit none
@@ -202,9 +202,9 @@ contains
202202

203203
! Check that the tensor values are all one
204204
expected(:,:) = 1.0
205-
@assertTrue(allclose(out_data, expected, test_name="test_torch_tensor_ones"))
205+
@assertTrue(allclose(out_data, expected, test_name="test_ones"))
206206

207-
end subroutine test_torch_tensor_ones
207+
end subroutine test_ones
208208

209209
! Unit test for the torch_tensor_from_array subroutine in the 1D case
210210
@test(testParameters={get_parameters_requires_grad()})
@@ -243,7 +243,7 @@ contains
243243
tensor2 = tensor1
244244

245245
! Compare the data in the tensor to the input data
246-
@assertTrue(allclose(out_data, in_data, test_name="test_torch_tensor_from_array"))
246+
@assertTrue(allclose(out_data, in_data, test_name="test_from_array"))
247247

248248
end subroutine test_torch_from_array_1d
249249

@@ -295,7 +295,7 @@ contains
295295

296296
! Compare the data in the tensor to the (reordered) input data
297297
expected(:,:) = reshape(in_data, [2,3], order=tensor_layout)
298-
@assertTrue(allclose(out_data, expected, test_name="test_torch_tensor_from_array"))
298+
@assertTrue(allclose(out_data, expected, test_name="test_from_array"))
299299

300300
end subroutine test_torch_from_array_2d
301301

@@ -347,7 +347,7 @@ contains
347347

348348
! Compare the data in the tensor to the (reordered) input data
349349
expected(:,:,:) = reshape(in_data, [1,2,3], order=tensor_layout)
350-
@assertTrue(allclose(out_data, expected, test_name="test_torch_tensor_from_array"))
350+
@assertTrue(allclose(out_data, expected, test_name="test_from_array"))
351351

352352
end subroutine test_torch_from_array_3d
353353

@@ -388,14 +388,14 @@ contains
388388
tensor2 = tensor1
389389

390390
! Compare the data in the tensor to the input data
391-
@assertTrue(allclose(out_data, in_data, test_name="test_torch_tensor_from_blob"))
391+
@assertTrue(allclose(out_data, in_data, test_name="test_from_blob"))
392392

393393
end subroutine test_torch_from_blob
394394

395395
! Unit test for destroying tensors, both manually with torch_tensor_delete and automatically (via
396396
! torch_tensor's destructor)
397397
@test(testparameters={get_parameters_destruction()})
398-
subroutine test_torch_tensor_destruction(this)
398+
subroutine test_destruction(this)
399399
use ftorch_tensor, only: torch_tensor_empty
400400

401401
implicit none
@@ -427,6 +427,6 @@ contains
427427

428428
end do
429429

430-
end subroutine test_torch_tensor_destruction
430+
end subroutine test_destruction
431431

432432
end module unittest_tensor_constructors_destructors

test/unit/tensor/unittest_tensor_interrogation_cuda.pf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ contains
2525

2626
! Unit test for the torch_tensor_get_device_type function applied to a tensor on a CUDA device
2727
@test
28-
subroutine test_torch_tensor_get_device_type()
28+
subroutine test_get_device_type()
2929

3030
implicit none
3131

@@ -39,12 +39,12 @@ contains
3939
call torch_tensor_empty(tensor, ndims, tensor_shape, dtype, device_type)
4040
@assertEqual(expected, tensor%get_device_type())
4141

42-
end subroutine test_torch_tensor_get_device_type
42+
end subroutine test_get_device_type
4343

4444
! Unit test for the torch_tensor_get_device_index function applied to a tensor on a CUDA device
4545
! Tensor is created without specifying a device_index so should default to device 0
4646
@test
47-
subroutine test_torch_tensor_get_device_index_default()
47+
subroutine test_get_device_index_default()
4848

4949
implicit none
5050

@@ -58,6 +58,6 @@ contains
5858
call torch_tensor_empty(tensor, ndims, tensor_shape, dtype, device_type)
5959
@assertEqual(expected, tensor%get_device_index())
6060

61-
end subroutine test_torch_tensor_get_device_index_default
61+
end subroutine test_get_device_index_default
6262

6363
end module unittest_tensor_interrogation_cuda

test/unit/tensor/unittest_tensor_manipulation.pf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ contains
2222

2323
! Unit test for the torch_tensor_zero subroutine
2424
@test
25-
subroutine test_torch_tensor_zero()
25+
subroutine test_zero()
2626
use, intrinsic :: iso_fortran_env, only: sp => real32
2727

2828
! Set working precision for reals
@@ -45,8 +45,8 @@ contains
4545

4646
! Compare the data in the tensor to the input array
4747
expected(:,:) = 0.0
48-
@assertTrue(allclose(in_data, expected, test_name="test_torch_tensor_zero"))
48+
@assertTrue(allclose(in_data, expected, test_name="test_zero"))
4949

50-
end subroutine test_torch_tensor_zero
50+
end subroutine test_zero
5151

5252
end module unittest_tensor_manipulation

test/unit/tensor/unittest_tensor_manipulation_cuda.pf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ contains
2222
! Unit test for the torch_tensor_to subroutine moving a tensor from the CPU (Float64) to a CUDA
2323
! device (Float32)
2424
@test
25-
subroutine test_torch_tensor_to()
25+
subroutine test_to()
2626
use, intrinsic :: iso_fortran_env, only: sp => real32, dp => real64
2727

28-
type(torch_tensor) :: cpu_tensor, gpu_tensor, test_tensor
28+
type(torch_tensor) :: cpu_tensor, gpu_tensor, temp
2929
real(dp), dimension(2,3,4) :: dp_data
3030
real(sp), dimension(2,3,4) :: sp_data_expected, temp_array
3131
integer, parameter :: device_type_source = torch_kCPU
@@ -55,15 +55,15 @@ contains
5555
@assertTrue(gpu_tensor%get_rank() == cpu_tensor%get_rank())
5656

5757
! Temporary torch_tensor for testing created from array to extract underlying values
58-
call torch_tensor_from_array(test_tensor, temp_array, device_type_source)
58+
call torch_tensor_from_array(temp, temp_array, device_type_source)
5959

6060
! Move back to CPU for comparison
61-
call torch_tensor_to(gpu_tensor, test_tensor)
61+
call torch_tensor_to(gpu_tensor, temp)
6262

6363
! Cast the data cpu_tensor is holding in double precision to single precision to
6464
! do the comparison with the data held by gpu_tensor (via temp_array)
65-
sp_data_expected = real(dp_data, sp)
66-
if (.not. allclose(temp_array, sp_data_expected, "test_torch_tensor_to")) then
65+
sp_data_expected = real(dp_data, sp)
66+
if (.not. allclose(temp_array, sp_data_expected, "test_to")) then
6767
print *, "Error :: incorrect output from torch_tensor_to"
6868
print *, "Source Tensor:"
6969
call torch_tensor_print(cpu_tensor)
@@ -72,6 +72,6 @@ contains
7272
stop 999
7373
end if
7474

75-
end subroutine test_torch_tensor_to
75+
end subroutine test_to
7676

7777
end module unittest_tensor_manipulation_cuda

0 commit comments

Comments
 (0)