def test_psd1(self): token = str(uuid.uuid4()) self.responses.add( responses.GET, f"https://gwcloud.org.au/bilby/file_download/?fileId={token}", body=open(Path(__file__).parent.resolve() / 'data/psd.txt', 'rb').read(), status=200 ) supporting_files = [ { 'type': 'psd', 'key': 'V1', 'file_name': 'test.psd', 'token': token } ] from core.submit import bilby_ini_to_args, prepare_supporting_files with TemporaryDirectory() as working_directory, cd(working_directory): args = bilby_ini_to_args(self.ini_file) prepare_supporting_files(args, supporting_files, working_directory) for supporting_file in supporting_files: self.assertTrue( ( Path(working_directory) / 'supporting_files' / supporting_file['type'] / supporting_file['file_name'] ).is_file() ) args = self.perform_ini_save_load_cycle(args) self.assertDictEqual(args.psd_dict, {'V1': './supporting_files/psd/test.psd'})
def test_numerical_relativity_file(self): token = str(uuid.uuid4()) self.responses.add( responses.GET, f"https://gwcloud.org.au/bilby/file_download/?fileId={token}", body=self.content.encode('utf-8'), status=200 ) supporting_files = [ { 'type': 'nmr', 'key': None, 'file_name': 'test.nmr', 'token': token } ] from core.submit import bilby_ini_to_args, prepare_supporting_files with TemporaryDirectory() as working_directory, cd(working_directory): args = bilby_ini_to_args(self.ini_file) prepare_supporting_files(args, supporting_files, working_directory) for supporting_file in supporting_files: self.assertTrue( ( Path(working_directory) / 'supporting_files' / supporting_file['type'] / supporting_file['file_name'] ).is_file() ) args = self.perform_ini_save_load_cycle(args) self.assertEqual(args.numerical_relativity_file, './supporting_files/nmr/test.nmr')
def test_cal1(self): token = str(uuid.uuid4()) self.responses.add( responses.GET, f"https://gwcloud.org.au/bilby/file_download/?fileId={token}", body=self.content.encode('utf-8'), status=200 ) supporting_files = [ { 'type': 'cal', 'key': 'V1', 'file_name': 'test.cal', 'token': token } ] from core.submit import bilby_ini_to_args, prepare_supporting_files with TemporaryDirectory() as working_directory, cd(working_directory): args = bilby_ini_to_args(self.ini_file) prepare_supporting_files(args, supporting_files, working_directory) for supporting_file in supporting_files: self.assertTrue( ( Path(working_directory) / 'supporting_files' / supporting_file['type'] / supporting_file['file_name'] ).is_file() ) args = self.perform_ini_save_load_cycle(args) self.assertDictEqual(args.spline_calibration_envelope_dict, {'V1': './supporting_files/cal/test.cal'})
def test_start_app(new_project, cov_env): proj_path = new_project('xxx') print(proj_path) with cd(proj_path): app_name = 'yyy' call('manage.py', f'startapp {app_name}', cov_env) prefix = f'apps/{app_name}/' for ff in ('', 'app.py', 'extension.py', '__init__.py', 'handler.py'): ff = os.path.join(prefix, ff) assert os.path.exists(ff)
def test(self): ret = main(["add", "data_dir/data"]) self.assertEqual(ret, 0) with cd("data_dir"): ret = main(["move", "data", "data.txt"]) self.assertEqual(ret, 0) self.assertFalse(os.path.exists("data_dir/data")) self.assertTrue(os.path.exists("data_dir/data.txt")) self.assertTrue(os.path.exists("data_dir/data.txt.dvc"))
def test_timeslide_gps_file(self): token = str(uuid.uuid4()) self.responses.add( responses.GET, f"https://gwcloud.org.au/bilby/file_download/?fileId={token}", body=open(Path(__file__).parent.resolve() / 'data/gps_file_for_timeslides.txt', 'rb').read(), status=200 ) token2 = str(uuid.uuid4()) self.responses.add( responses.GET, f"https://gwcloud.org.au/bilby/file_download/?fileId={token2}", body=open(Path(__file__).parent.resolve() / 'data/timeslides.txt', 'rb').read(), status=200 ) supporting_files = [ { 'type': 'gps', 'key': None, 'file_name': 'test.gps', 'token': token }, { 'type': 'tsl', 'key': None, 'file_name': 'test.timeslide', 'token': token2 } ] from core.submit import bilby_ini_to_args, prepare_supporting_files with TemporaryDirectory() as working_directory, cd(working_directory): args = bilby_ini_to_args(self.ini_file) prepare_supporting_files(args, supporting_files, working_directory) for supporting_file in supporting_files: self.assertTrue( ( Path(working_directory) / 'supporting_files' / supporting_file['type'] / supporting_file['file_name'] ).is_file() ) args = self.perform_ini_save_load_cycle(args) self.assertTrue(args.gps_file.endswith('supporting_files/gps/test.gps')) self.assertTrue(args.timeslide_file.endswith('supporting_files/tsl/test.timeslide'))
def test(self): ret = main(["add", self.DATA]) self.assertEqual(ret, 0) with cd(self.DATA_DIR): ret = main(["move", os.path.basename(self.DATA), "data.txt"]) self.assertEqual(ret, 0) self.assertFalse(os.path.exists(self.DATA)) data_fullpath = os.path.join(self.DATA_DIR, "data.txt") dvc_fullpath = os.path.join(self.DATA_DIR, "data.txt.dvc") self.assertTrue(os.path.exists(data_fullpath)) self.assertTrue(os.path.exists(dvc_fullpath))
def create_project(tmpdir, proj_name, app_name=None): f = 'cmd_runner.py' runf = os.path.join(tmpdir.strpath, f) copy_file(f, runf) env = os.environ.copy() env['COVERAGE_PROCESS_START'] = os.path.abspath('.coveragerc') env['COVERAGE_FILE'] = os.path.abspath('.coverage') cmd = f'startproject {proj_name}' if app_name: cmd += f' --with-app {app_name}' with cd(tmpdir): call(runf, cmd, env)
def test_info(new_project, cov_env): proj_name = 'xxx' app_name = 'example' proj_path = new_project(proj_name, app_name) print(proj_path) expect = [ f'"name": "{app_name}",', f'"package": "apps.{app_name}",', f'<class \'apps.{app_name}.extension.{app_name.capitalize()}\'>', f'<class \'apps.{app_name}.handler.{app_name.capitalize()}View\'>', ] with cd(proj_path): stdout, _ = call('manage.py', 'info', cov_env) for exp in expect: assert exp.encode() in stdout
def _create_project(proj_name, app_name=None): create_project(tmpdir, proj_name, app_name) proj_path = os.path.join(tmpdir.strpath, proj_name) with cd(proj_path): copy_file('manage_for_test.py', 'manage.py') return proj_path