Skip to content

Commit ebc50dc

Browse files
authored
Update perturbIC_test.py
Edit the pytests to improve the commenting
1 parent 880b393 commit ebc50dc

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

tests/perturbIC_test.py

+17-25
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,14 @@ def mock_metadata():
4141
Outputs
4242
list - Command line arguements
4343
"""
44-
metadata_index_false = Mock()
45-
metadata_index_true = Mock()
46-
47-
metadata_index_false.lbuser4 = 24
48-
metadata_index_true.lbuser4 = -99
49-
44+
45+
metadata_index_false = 24
46+
metadata_index_true = -99
47+
5048
end_of_data = -99
5149

5250
return metadata_index_false, metadata_index_true, end_of_data
5351

54-
#Test the Imports may not be necessary
5552
def test_parse_args(monkeypatch, mock_command_line):
5653
"""
5754
This function tests the parse_args function with the fake commandline arguments
@@ -67,16 +64,7 @@ def test_parse_args(monkeypatch, mock_command_line):
6764
assert args.amplitude == 0.4
6865
assert args.seed == 23452
6966
assert args.output == "restart_dump_copy_perturb.astart"
70-
#Test checking the seed
71-
#def test_set_seed(args):
72-
#Not sure if we need test but the conditionals in a function is nice.
73-
74-
75-
#Test creating output file
76-
#def test_creating_output_file():
77-
7867

79-
#Test the random generator
8068
def test_create_perturbation(monkeypatch, mock_command_line, mock_perturbation):
8169
"""
8270
This function tests the create_perturbation function with the fake commandline arguments
@@ -109,7 +97,7 @@ def test_is_end_of_file_keep_going(mock_metadata):
10997
assert is_end_of_file(metadata_index_true, end_of_data) == True
11098

11199

112-
#Test that the perturbation has been applied
100+
113101
def test_applying_perturbation(mock_perturbation):
114102

115103
"""
@@ -124,26 +112,30 @@ def test_applying_perturbation(mock_perturbation):
124112
The results of assertion tests.
125113
"""
126114

127-
#Create random perturbation
115+
# Create random perturbation
128116
nlon, nlat = mock_perturbation
129117
perturbation = 0.5 * (2.*rs.random(nlon*nlat).reshape((nlat,nlon))-1.)
130118
perturbation[0] = 0
131119
perturbation[-1] = 0
132-
stash_code = 24
120+
stash_code = 4
133121

134-
#Create a fake data array to simulate the numpy array that is
135-
#To mock the method readfld that reads the field corresponding
136-
#To the itemcode
137-
122+
# Create a fake data array to simulate the numpy array that is
123+
# To mock the method readfld that reads the field corresponding to the itemcode
124+
138125
shape = (nlat, nlon)
139126
field_theta = Mock()
140127
field_not_theta = Mock()
141128

142-
field_theta.lbuser4 = 24
129+
field_theta.lbuser4 = 4
143130
field_not_theta.lbuser4 = 3
144-
#Testing if the perturb conditional works and if the resulting array is correct
131+
132+
# Testing if the perturb conditional works and if the resulting array is correct
133+
145134
#testing_a = np.round((perturbed_array - perturb) / np.ones(shape),0)
146135
assert do_perturb(field_theta, stash_code) == True
147136
assert do_perturb(field_not_theta, stash_code) == False
148137
#assert perturbed_array.shape == (nlat, nlon)
149138
#assert testing_a.all() == 1.
139+
140+
148,0-1 Bot
141+

0 commit comments

Comments
 (0)