def test_run(capsys): # test invalid input invalid = [None, 5, 1.0] for i in invalid: pytest.raises(OpenL3Error, run, i, i) # test empty input folder with pytest.raises(SystemExit) as pytest_wrapped_e: tempdir = tempfile.mkdtemp() run('audio', [tempdir]) # make sure it exited assert pytest_wrapped_e.type == SystemExit assert pytest_wrapped_e.value.code == -1 # make sure it printed a message captured = capsys.readouterr() expected_message = 'openl3: No files found in {}. Aborting.\n'.format(str([tempdir])) assert captured.out == expected_message # delete tempdir if os.path.exists(tempdir): os.rmdir(tempdir) # test invalid modality with pytest.raises(OpenL3Error) as pytest_wrapped_e: tempdir = tempfile.mkdtemp() run('invalid', CHIRP_44K_PATH, output_dir=tempdir) # delete tempdir if os.path.exists(tempdir): os.rmdir(tempdir)
def test_audio_regression(capsys): # test correct execution on test audio file (regression) tempdir = tempfile.mkdtemp() run('audio', CHIRP_44K_PATH, output_dir=tempdir, verbose=True) # check output file created audio_outfile = os.path.join(tempdir, 'chirp_44k.npz') assert os.path.isfile(audio_outfile) # regression test audio_data_reg = np.load(REG_CHIRP_44K_PATH) audio_data_out = np.load(audio_outfile) assert sorted(audio_data_out.files) == sorted( audio_data_reg.files) == sorted(['embedding', 'timestamps']) assert np.allclose(audio_data_out['timestamps'], audio_data_reg['timestamps'], rtol=1e-05, atol=1e-05, equal_nan=False) assert np.allclose(audio_data_out['embedding'], audio_data_reg['embedding'], rtol=1e-05, atol=1e-05, equal_nan=False) # SECOND regression test run('audio', CHIRP_44K_PATH, output_dir=tempdir, suffix='linear', input_repr='linear', content_type='env', audio_embedding_size=512, audio_center=False, audio_hop_size=0.5, verbose=False) # check output file created audio_outfile = os.path.join(tempdir, 'chirp_44k_linear.npz') assert os.path.isfile(audio_outfile) # regression test audio_data_reg = np.load(REG_CHIRP_44K_LINEAR_PATH) audio_data_out = np.load(audio_outfile) assert sorted(audio_data_out.files) == sorted( audio_data_reg.files) == sorted(['embedding', 'timestamps']) assert np.allclose(audio_data_out['timestamps'], audio_data_reg['timestamps'], rtol=1e-05, atol=1e-05, equal_nan=False) assert np.allclose(audio_data_out['embedding'], audio_data_reg['embedding'], rtol=1e-05, atol=1e-05, equal_nan=False) # delete output file and temp folder shutil.rmtree(tempdir)
def test_image_regression(capsys): # test correct execution on test image file (regression) tempdir = tempfile.mkdtemp() run('image', DAISY_PATH, output_dir=tempdir, verbose=True) # check output file created image_outfile = os.path.join(tempdir, 'daisy.npz') assert os.path.isfile(image_outfile) # regression test image_data_reg = np.load(REG_DAISY_PATH) image_data_out = np.load(image_outfile) assert sorted(image_data_out.files) == sorted( image_data_reg.files) == ['embedding'] assert np.allclose(image_data_out['embedding'], image_data_reg['embedding'], rtol=1e-05, atol=1e-05, equal_nan=False) # SECOND regression test run('image', DAISY_PATH, output_dir=tempdir, suffix='linear', input_repr='linear', content_type='env', image_embedding_size=512, verbose=False) # check output file created image_outfile = os.path.join(tempdir, 'daisy_linear.npz') assert os.path.isfile(image_outfile) # regression test image_data_reg = np.load(REG_DAISY_LINEAR_PATH) image_data_out = np.load(image_outfile) assert sorted(image_data_out.files) == sorted( image_data_reg.files) == ['embedding'] assert np.allclose(image_data_out['embedding'], image_data_reg['embedding'], rtol=1e-05, atol=1e-05, equal_nan=False) # delete output file and temp folder shutil.rmtree(tempdir)
def test_video_regression(capsys): tempdir = tempfile.mkdtemp() ## Video processing regression tests run('video', BENTO_PATH, output_dir=tempdir, verbose=True) # check output files created audio_outfile = os.path.join(tempdir, 'bento_audio.npz') assert os.path.isfile(audio_outfile) image_outfile = os.path.join(tempdir, 'bento_image.npz') assert os.path.isfile(image_outfile) # regression test audio_data_reg = np.load(REG_BENTO_AUDIO_PATH) audio_data_out = np.load(audio_outfile) image_data_reg = np.load(REG_BENTO_IMAGE_PATH) image_data_out = np.load(image_outfile) assert sorted(audio_data_out.files) == sorted( audio_data_reg.files) == sorted(['embedding', 'timestamps']) assert np.allclose(audio_data_out['timestamps'], audio_data_reg['timestamps'], rtol=1e-05, atol=1e-05, equal_nan=False) assert np.allclose(audio_data_out['embedding'], audio_data_reg['embedding'], rtol=1e-05, atol=1e-05, equal_nan=False) assert sorted(image_data_out.files) == sorted( image_data_reg.files) == sorted(['embedding', 'timestamps']) assert np.allclose(image_data_out['timestamps'], image_data_reg['timestamps'], rtol=1e-05, atol=1e-05, equal_nan=False) assert np.allclose(image_data_out['embedding'], image_data_reg['embedding'], rtol=1e-05, atol=1e-05, equal_nan=False) # SECOND regression test run('video', BENTO_PATH, output_dir=tempdir, suffix='linear', input_repr='linear', content_type='env', audio_embedding_size=512, image_embedding_size=512, audio_center=False, audio_hop_size=0.5, verbose=False) # check output files created audio_outfile = os.path.join(tempdir, 'bento_audio_linear.npz') assert os.path.isfile(audio_outfile) image_outfile = os.path.join(tempdir, 'bento_image_linear.npz') assert os.path.isfile(image_outfile) # regression test audio_data_reg = np.load(REG_BENTO_AUDIO_LINEAR_PATH) audio_data_out = np.load(audio_outfile) image_data_reg = np.load(REG_BENTO_IMAGE_LINEAR_PATH) image_data_out = np.load(image_outfile) assert sorted(audio_data_out.files) == sorted( audio_data_reg.files) == sorted(['embedding', 'timestamps']) assert np.allclose(audio_data_out['timestamps'], audio_data_reg['timestamps'], rtol=1e-05, atol=1e-05, equal_nan=False) assert np.allclose(audio_data_out['embedding'], audio_data_reg['embedding'], rtol=1e-05, atol=1e-05, equal_nan=False) assert sorted(image_data_out.files) == sorted( image_data_reg.files) == sorted(['embedding', 'timestamps']) assert np.allclose(image_data_out['timestamps'], image_data_reg['timestamps'], rtol=1e-05, atol=1e-05, equal_nan=False) assert np.allclose(image_data_out['embedding'], image_data_reg['embedding'], rtol=1e-05, atol=1e-05, equal_nan=False)
def test_run(capsys): # test invalid input invalid = [None, 5, 1.0] for i in invalid: pytest.raises(OpenL3Error, run, i) # test empty input folder with pytest.raises(SystemExit) as pytest_wrapped_e: tempdir = tempfile.mkdtemp() run([tempdir]) # make sure it exited assert pytest_wrapped_e.type == SystemExit assert pytest_wrapped_e.value.code == -1 # make sure it printed a message captured = capsys.readouterr() expected_message = 'openl3: No WAV files found in {}. Aborting.\n'.format( str([tempdir])) assert captured.out == expected_message # detele tempdir os.rmdir(tempdir) # test correct execution on test file (regression) tempdir = tempfile.mkdtemp() run(CHIRP_44K_PATH, output_dir=tempdir, verbose=True) # check output file created outfile = os.path.join(tempdir, 'chirp_44k.npz') assert os.path.isfile(outfile) # regression test data_reg = np.load(REG_CHIRP_44K_PATH) data_out = np.load(outfile) assert sorted(data_out.files) == sorted(data_out.files) == sorted( ['embedding', 'timestamps']) assert np.allclose(data_out['timestamps'], data_reg['timestamps']) assert np.allclose(data_out['embedding'], data_reg['embedding']) # SECOND regression test run(CHIRP_44K_PATH, output_dir=tempdir, suffix='linear', input_repr='linear', content_type='env', embedding_size=512, center=False, hop_size=0.5, verbose=False) # check output file created outfile = os.path.join(tempdir, 'chirp_44k_linear.npz') assert os.path.isfile(outfile) # regression test data_reg = np.load(REG_CHIRP_44K_LINEAR_PATH) data_out = np.load(outfile) assert sorted(data_out.files) == sorted(data_out.files) == sorted( ['embedding', 'timestamps']) assert np.allclose(data_out['timestamps'], data_reg['timestamps']) assert np.allclose(data_out['embedding'], data_reg['embedding']) # delete output file and temp folder shutil.rmtree(tempdir)