1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
From: Ole Streicher <olebole@debian.org>
Date: Fri, 18 Sep 2020 16:23:11 +0200
Subject: Write test output to temporary file
URL: https://github.com/radio-astro-tools/spectral-cube/issues/451
(modified for 0.5.0)
---
spectral_cube/tests/test_wcs_utils.py | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/spectral_cube/tests/test_wcs_utils.py b/spectral_cube/tests/test_wcs_utils.py
index 720dfa8..2e0bc25 100644
--- a/spectral_cube/tests/test_wcs_utils.py
+++ b/spectral_cube/tests/test_wcs_utils.py
@@ -2,6 +2,8 @@ from __future__ import print_function, absolute_import, division
import pytest
import warnings
+import os
+import tempfile
from astropy.io import fits
import numpy as np
@@ -156,16 +158,17 @@ def test_strip_wcs(fn):
with open(path(fn),'r') as fh:
hdrlines = fh.readlines()
- newfn = fn.replace('.hdr', '_blanks.hdr')
+ fd, newfn = tempfile.mkstemp(suffix='.hdr')
hdrlines.insert(-20,"\n")
hdrlines.insert(-1,"\n")
- with open(path(newfn),'w') as fh:
+ with os.fdopen(fd,'w') as fh:
fh.writelines(hdrlines)
header2 = fits.Header.fromtextfile(path(newfn))
header2_stripped = strip_wcs_from_header(header2)
+ os.remove(newfn)
assert header1_stripped == header2_stripped
def test_wcs_slice_unmatched_celestial():
|