def test_help(test_file): """ Tests the helper displays for commands in main""" # expected helper messages with open(os.path.join(TESTDATA_DIR, 'too_few_arguments_help.txt'), 'r') \ as myfile: too_few_arguments_usage = myfile.read() with open(os.path.join(TESTDATA_DIR, 'help.txt'), 'r') as myfile: usage = myfile.read() with open(os.path.join(TESTDATA_DIR, 'missing_observation_help.txt'), 'r')\ as myfile: myfile.read() with open(os.path.join(TESTDATA_DIR, 'missing_positional_argument_help.txt'), 'r') \ as myfile: myfile.read() # too few arguments error message when running python3 with patch('sys.stdout', new_callable=StringIO) as stdout_mock: sys.argv = ["fits2caom2"] with pytest.raises(MyExitError): main_app() if stdout_mock.getvalue(): assert (too_few_arguments_usage == stdout_mock.getvalue()) # --help with patch('sys.stdout', new_callable=StringIO) as stdout_mock: sys.argv = ["fits2caom2", "-h"] with pytest.raises(MyExitError): main_app() assert (usage == stdout_mock.getvalue()) # missing required --observation """
def test_file_scheme_uris(): """ Tests that local files as URIs will be accepted and processed.""" fname = 'file://{}'.format(sample_file_4axes) with patch('sys.stdout', new_callable=BytesIO) as stdout_mock: sys.argv = [ 'fits2caom2', '--observation', 'test_collection_id', 'test_observation_id', '--productID', 'test_product_id', '--config', java_config_file, '--override', test_override, fname ] main_app() if stdout_mock.getvalue(): expected = _get_obs(EXPECTED_FILE_SCHEME_XML) actual = _get_obs(stdout_mock.getvalue().decode('ascii')) result = get_differences(expected, actual, 'Observation') assert result is None
def test_generic_parser(): """ Tests that GenericParser will be created.""" fname = 'file://{}'.format(text_file) with patch('sys.stdout', new_callable=BytesIO) as stdout_mock: sys.argv = [ 'fits2caom2', '--local', fname, '--observation', 'test_collection_id', 'test_observation_id', '--productID', 'test_product_id', '--config', java_config_file, '--override', text_override, fname ] main_app() if stdout_mock.getvalue(): expected = _get_obs(EXPECTED_GENERIC_PARSER_FILE_SCHEME_XML) actual = _get_obs(stdout_mock.getvalue().decode('ascii')) result = get_differences(expected, actual, 'Observation') assert result is None
def test_valid_arguments(test_file): """ Tests the parser with valid commands in main""" # --in with patch('sys.stderr', new_callable=StringIO) as stdout_mock: sys.argv = ["fits2caom2", "--in", "pathTo/inObsXML", "productID", "pathTo/testFileURI1", "pathTo/testFileURI2"] main_app() help_out = stdout_mock.getvalue() assert(not stdout_mock.getvalue()) # --in and --out with patch('sys.stderr', new_callable=StringIO) as stdout_mock: sys.argv = ["fits2caom2", "--in", "pathTo/inObsXML", "--out", "pathTo/outObsXML", "productID", "pathTo/testFileURI1", "pathTo/testFileURI2"] main_app() help_out = stdout_mock.getvalue() assert(not stdout_mock.getvalue()) # --observation with patch('sys.stderr', new_callable=StringIO) as stdout_mock: sys.argv = ["fits2caom2", "--observation", "testCollection", "testObservationID", "productID", "pathTo/testFileURI1", "pathTo/testFileURI2"] main_app() help_out = stdout_mock.getvalue() assert(not stdout_mock.getvalue()) # --observation and --out with patch('sys.stderr', new_callable=StringIO) as stdout_mock: sys.argv = ["fits2caom2", "--observation", "testCollection", "testObservationID", "--out", "pathTo/outObsXML" "productID", "pathTo/testFileURI1", "pathTo/testFileURI2"] main_app() help_out = stdout_mock.getvalue() assert(not stdout_mock.getvalue())
def test_help(): """ Tests the helper displays for commands in main""" # expected helper messages with open(os.path.join(TESTDATA_DIR, 'bad_product_id.txt'), 'r') \ as myfile: bad_product_id = myfile.read() with open(os.path.join(TESTDATA_DIR, 'missing_product_id.txt'), 'r') \ as myfile: missing_product_id = myfile.read() with open(os.path.join(TESTDATA_DIR, 'too_few_arguments_help.txt'), 'r') \ as myfile: too_few_arguments_usage = myfile.read() with open(os.path.join(TESTDATA_DIR, 'help.txt'), 'r') as myfile: usage = myfile.read() with open(os.path.join(TESTDATA_DIR, 'missing_observation_help.txt'), 'r')\ as myfile: myfile.read() with open(os.path.join(TESTDATA_DIR, 'missing_positional_argument_help.txt'), 'r') \ as myfile: myfile.read() # too few arguments error message when running python3 with patch('sys.stdout', new_callable=StringIO) as stdout_mock: sys.argv = ["fits2caom2"] with pytest.raises(MyExitError): main_app() if stdout_mock.getvalue(): assert (too_few_arguments_usage == stdout_mock.getvalue()) # --help with patch('sys.stdout', new_callable=StringIO) as stdout_mock: sys.argv = ["fits2caom2", "-h"] with pytest.raises(MyExitError): main_app() assert (usage == stdout_mock.getvalue()) # missing productID when plane count is wrong with patch('sys.stderr', new_callable=StringIO) as stderr_mock: bad_product_file = os.path.join(TESTDATA_DIR, 'bad_product_id.xml') sys.argv = [ "fits2caom2", "--in", bad_product_file, "ad:CGPS/CGPS_MA1_HI_line_image.fits" ] with pytest.raises(MyExitError): main_app() assert bad_product_id == stderr_mock.getvalue() # missing productID when blueprint doesn't have one either with patch('sys.stderr', new_callable=StringIO) as stderr_mock: sys.argv = [ "fits2caom2", "--observation", "test_collection_id", "test_observation_id", "ad:CGPS/CGPS_MA1_HI_line_image.fits" ] with pytest.raises(MyExitError): main_app() assert missing_product_id == stderr_mock.getvalue() # missing required --observation """