Skip to content

Commit

Permalink
handle missing env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverba137 committed Nov 10, 2023
1 parent 7056890 commit a22de88
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions py/desitransfer/spacewatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def _options():
prsr.add_argument('-o', '--overwrite', action='store_true',
help='Overwrite any existing files.')
prsr.add_argument('-s', '--server', metavar='SERVER',
default=os.environ['SPACEWATCH_SERVER'],
default=os.getenv('SPACEWATCH_SERVER', 'SPACEWATCH_SERVER'),
help='Set the Spacwatch server name to SERVER (default "%(default)s").')
prsr.add_argument('-t', '--test', action='store_true',
help='Do not actually download any files; implies --debug.')
Expand All @@ -158,7 +158,7 @@ def main():
log = get_logger(DEBUG)
else:
log = get_logger()
if options.server is None:
if options.server == 'SPACEWATCH_SERVER':
log.critical("Spacewatch server name is not set!")
return 1
spacewatch_root = f'https://{options.server}/allsky-all/images/cropped/'
Expand Down
12 changes: 11 additions & 1 deletion py/desitransfer/test/test_spacewatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,19 @@ def tearDown(self):
def test_options(self):
"""Test command-line arguments.
"""
with patch.object(sys, 'argv', ['desi_spacewatch_transfer', '--debug', '/desi/external/spacewatch']):
with patch.dict('os.environ', {'SPACEWATCH_SERVER': 'www.example.com'}):
options = _options()
self.assertTrue(options.debug)
self.assertEqual(options.server, 'www.example.com')

def test_options_bad_env(self):
"""Test command-line arguments with missing env variable.
"""
with patch.object(sys, 'argv', ['desi_spacewatch_transfer', '--debug', '/desi/external/spacewatch']):
options = _options()
self.assertTrue(options.debug)
self.assertTrue(options.debug)
self.assertEqual(options.server, 'SPACEWATCH_SERVER')

@patch('desitransfer.spacewatch.requests')
def test_jpg_files(self, mock_requests):
Expand Down

0 comments on commit a22de88

Please sign in to comment.