1010from unittest .mock import patch
1111import io
1212
13- def test_without_species_list ():
13+ TEST_BN_COMMIT = "98945574c68102ccfac6c3504fcc63e64ed6f9e3"
14+
1415
16+ def test_without_species_list ():
1517 # Process file with command line utility, then process with python library and ensure equal commandline_results.
1618
1719 lon = - 120.7463
@@ -24,6 +26,9 @@ def test_without_species_list():
2426
2527 # Process using python script as is.
2628 birdnet_analyzer_path = os .path .join (os .path .dirname (__file__ ), "BirdNET-Analyzer" )
29+ os .system (
30+ f"cd { birdnet_analyzer_path } ; git clean -fd; git checkout { TEST_BN_COMMIT } ; git status"
31+ )
2732
2833 cmd = f"python analyze.py --i '{ input_path } ' --o={ output_path } --lat { lat } --lon { lon } --week { week_48 } --min_conf { min_conf } --rtype=csv"
2934 print (cmd )
@@ -50,10 +55,10 @@ def test_without_species_list():
5055
5156 # pprint(commandline_results)
5257 assert len (commandline_results ) > 0
53- with open (input_path ,'rb' ) as f :
58+ with open (input_path , "rb" ) as f :
5459 wav_buffer = f .read ()
5560 bytes_buffer = io .BytesIO (wav_buffer )
56- for rate ,buffer in wavutils .bufferwavs (bytes_buffer ):
61+ for rate , buffer in wavutils .bufferwavs (bytes_buffer ):
5762 analyzer = Analyzer ()
5863 recording = RecordingBuffer (
5964 analyzer ,
@@ -78,7 +83,6 @@ def test_without_species_list():
7883
7984
8085def test_with_species_list_path ():
81-
8286 # Process file with command line utility, then process with python library and ensure equal commandline_results.
8387
8488 lon = - 120.7463
@@ -95,6 +99,9 @@ def test_with_species_list_path():
9599
96100 # Process using python script as is.
97101 birdnet_analyzer_path = os .path .join (os .path .dirname (__file__ ), "BirdNET-Analyzer" )
102+ os .system (
103+ f"cd { birdnet_analyzer_path } ; git clean -fd; git checkout { TEST_BN_COMMIT } ; git status"
104+ )
98105
99106 cmd = f"python analyze.py --i '{ input_path } ' --o={ output_path } --min_conf { min_conf } --slist { custom_list_path } --rtype=csv"
100107 os .system (f"cd { birdnet_analyzer_path } ; { cmd } " )
@@ -120,10 +127,10 @@ def test_with_species_list_path():
120127
121128 pprint (commandline_results )
122129 assert len (commandline_results ) > 0
123- with open (input_path ,'rb' ) as f :
130+ with open (input_path , "rb" ) as f :
124131 wav_buffer = f .read ()
125132 bytes_buffer = io .BytesIO (wav_buffer )
126- for rate ,buffer in wavutils .bufferwavs (bytes_buffer ):
133+ for rate , buffer in wavutils .bufferwavs (bytes_buffer ):
127134 analyzer = Analyzer (custom_species_list_path = custom_list_path )
128135 recording = RecordingBuffer (
129136 analyzer ,
@@ -139,7 +146,8 @@ def test_with_species_list_path():
139146 pprint (recording .detections )
140147
141148 assert (
142- commandline_results [0 ]["common_name" ] == recording .detections [0 ]["common_name" ]
149+ commandline_results [0 ]["common_name" ]
150+ == recording .detections [0 ]["common_name" ]
143151 )
144152
145153 commandline_birds = [i ["common_name" ] for i in commandline_results ]
@@ -151,11 +159,11 @@ def test_with_species_list_path():
151159 len (analyzer .custom_species_list ) == 41
152160 ) # Check that this matches the number printed by the cli version.
153161
154- with open (input_path ,'rb' ) as f :
162+ with open (input_path , "rb" ) as f :
155163 wav_buffer = f .read ()
156164 bytes_buffer = io .BytesIO (wav_buffer )
157165 # Run a recording without path and throw an error when used with custom species list.
158- for rate ,buffer in wavutils .bufferwavs (bytes_buffer ):
166+ for rate , buffer in wavutils .bufferwavs (bytes_buffer ):
159167 with pytest .raises (ValueError ):
160168 recording = RecordingBuffer (
161169 analyzer ,
@@ -170,7 +178,6 @@ def test_with_species_list_path():
170178
171179
172180def test_with_species_list ():
173-
174181 # Process file with command line utility, then process with python library and ensure equal commandline_results.
175182
176183 lon = - 120.7463
@@ -187,6 +194,9 @@ def test_with_species_list():
187194
188195 # Process using python script as is.
189196 birdnet_analyzer_path = os .path .join (os .path .dirname (__file__ ), "BirdNET-Analyzer" )
197+ os .system (
198+ f"cd { birdnet_analyzer_path } ; git clean -fd; git checkout { TEST_BN_COMMIT } ; git status"
199+ )
190200
191201 cmd = f"python analyze.py --i '{ input_path } ' --o={ output_path } --min_conf { min_conf } --slist { custom_list_path } --rtype=csv"
192202 os .system (f"cd { birdnet_analyzer_path } ; { cmd } " )
@@ -257,11 +267,11 @@ def test_with_species_list():
257267 "Zonotrichia albicollis_White-throated Sparrow" ,
258268 ]
259269
260- with open (input_path ,'rb' ) as f :
270+ with open (input_path , "rb" ) as f :
261271 wav_buffer = f .read ()
262272 bytes_buffer = io .BytesIO (wav_buffer )
263273 # Run a recording without path and throw an error when used with custom species list.
264- for rate ,buffer in wavutils .bufferwavs (bytes_buffer ):
274+ for rate , buffer in wavutils .bufferwavs (bytes_buffer ):
265275 analyzer = Analyzer (custom_species_list = custom_species_list )
266276 recording = RecordingBuffer (
267277 analyzer ,
@@ -277,7 +287,8 @@ def test_with_species_list():
277287 pprint (recording .detections )
278288
279289 assert (
280- commandline_results [0 ]["common_name" ] == recording .detections [0 ]["common_name" ]
290+ commandline_results [0 ]["common_name" ]
291+ == recording .detections [0 ]["common_name" ]
281292 )
282293
283294 commandline_birds = [i ["common_name" ] for i in commandline_results ]
@@ -290,11 +301,11 @@ def test_with_species_list():
290301 ) # Check that this matches the number printed by the cli version.
291302
292303 # Run a recording with lat/lon and throw an error when used with custom species list.
293- with open (input_path ,'rb' ) as f :
304+ with open (input_path , "rb" ) as f :
294305 wav_buffer = f .read ()
295306 bytes_buffer = io .BytesIO (wav_buffer )
296307 # Run a recording without path and throw an error when used with custom species list.
297- for rate ,buffer in wavutils .bufferwavs (bytes_buffer ):
308+ for rate , buffer in wavutils .bufferwavs (bytes_buffer ):
298309 with pytest .raises (ValueError ):
299310 recording = RecordingBuffer (
300311 analyzer ,
@@ -309,7 +320,6 @@ def test_with_species_list():
309320
310321
311322def test_species_list_calls ():
312-
313323 lon = - 120.7463
314324 lat = 35.4244
315325 week_48 = 18
@@ -324,11 +334,11 @@ def test_species_list_calls():
324334 "return_predicted_species_list" ,
325335 wraps = analyzer .return_predicted_species_list ,
326336 ) as wrapped_return_predicted_species_list :
327- with open (input_path ,'rb' ) as f :
337+ with open (input_path , "rb" ) as f :
328338 wav_buffer = f .read ()
329339 bytes_buffer = io .BytesIO (wav_buffer )
330340 # Run a recording without path and throw an error when used with custom species list.
331- for rate ,buffer in wavutils .bufferwavs (bytes_buffer ):
341+ for rate , buffer in wavutils .bufferwavs (bytes_buffer ):
332342 recording = RecordingBuffer (
333343 analyzer ,
334344 buffer ,
@@ -342,10 +352,10 @@ def test_species_list_calls():
342352 assert wrapped_return_predicted_species_list .call_count == 1
343353
344354 # Second recording with the same position/time should not regerate the species list.
345- with open (input_path ,'rb' ) as f :
355+ with open (input_path , "rb" ) as f :
346356 wav_buffer = f .read ()
347357 bytes_buffer = io .BytesIO (wav_buffer )
348- for rate ,buffer in wavutils .bufferwavs (bytes_buffer ):
358+ for rate , buffer in wavutils .bufferwavs (bytes_buffer ):
349359 recording = RecordingBuffer (
350360 analyzer ,
351361 buffer ,
0 commit comments