summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2017-10-23 14:13:33 +0200
committerTodd Gamblin <tgamblin@llnl.gov>2017-10-24 10:05:36 +0200
commitb98fc48273b4e2a6f0ae776a5956a7593db65cc5 (patch)
tree317c58822c7379ae6fd36912fcadc50231789ad9 /lib
parent0bb1eb32f2c002b4b9deb44815192b4299432fa8 (diff)
downloadspack-b98fc48273b4e2a6f0ae776a5956a7593db65cc5.tar.gz
spack-b98fc48273b4e2a6f0ae776a5956a7593db65cc5.tar.bz2
spack-b98fc48273b4e2a6f0ae776a5956a7593db65cc5.tar.xz
spack-b98fc48273b4e2a6f0ae776a5956a7593db65cc5.zip
log tests use tmpdir properly
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/test/llnl/util/log.py65
1 files changed, 35 insertions, 30 deletions
diff --git a/lib/spack/spack/test/llnl/util/log.py b/lib/spack/spack/test/llnl/util/log.py
index 4a43350f99..cdfbf21f44 100644
--- a/lib/spack/spack/test/llnl/util/log.py
+++ b/lib/spack/spack/test/llnl/util/log.py
@@ -32,36 +32,39 @@ from spack.util.executable import which
def test_log_python_output_with_python_stream(capsys, tmpdir):
# pytest's DontReadFromInput object does not like what we do here, so
# disable capsys or things hang.
- with capsys.disabled():
- with log_output('foo.txt'):
- print('logged')
+ with tmpdir.as_cwd():
+ with capsys.disabled():
+ with log_output('foo.txt'):
+ print('logged')
- with open('foo.txt') as f:
- assert f.read() == 'logged\n'
+ with open('foo.txt') as f:
+ assert f.read() == 'logged\n'
- assert capsys.readouterr() == ('', '')
+ assert capsys.readouterr() == ('', '')
def test_log_python_output_with_fd_stream(capfd, tmpdir):
- with log_output('foo.txt'):
- print('logged')
+ with tmpdir.as_cwd():
+ with log_output('foo.txt'):
+ print('logged')
- with open('foo.txt') as f:
- assert f.read() == 'logged\n'
+ with open('foo.txt') as f:
+ assert f.read() == 'logged\n'
- assert capfd.readouterr() == ('', '')
+ assert capfd.readouterr() == ('', '')
def test_log_python_output_and_echo_output(capfd, tmpdir):
- with log_output('foo.txt') as logger:
- with logger.force_echo():
- print('echo')
- print('logged')
+ with tmpdir.as_cwd():
+ with log_output('foo.txt') as logger:
+ with logger.force_echo():
+ print('echo')
+ print('logged')
- assert capfd.readouterr() == ('echo\n', '')
+ assert capfd.readouterr() == ('echo\n', '')
- with open('foo.txt') as f:
- assert f.read() == 'echo\nlogged\n'
+ with open('foo.txt') as f:
+ assert f.read() == 'echo\nlogged\n'
@pytest.mark.skipif(not which('echo'), reason="needs echo command")
@@ -72,24 +75,26 @@ def test_log_subproc_output(capsys, tmpdir):
# TODO: figure out why this is and whether it means we're doing
# sometihng wrong with OUR redirects. Seems like it should work even
# with capsys enabled.
- with capsys.disabled():
- with log_output('foo.txt'):
- echo('logged')
+ with tmpdir.as_cwd():
+ with capsys.disabled():
+ with log_output('foo.txt'):
+ echo('logged')
- with open('foo.txt') as f:
- assert f.read() == 'logged\n'
+ with open('foo.txt') as f:
+ assert f.read() == 'logged\n'
@pytest.mark.skipif(not which('echo'), reason="needs echo command")
def test_log_subproc_and_echo_output(capfd, tmpdir):
echo = which('echo')
- with log_output('foo.txt') as logger:
- with logger.force_echo():
- echo('echo')
- print('logged')
+ with tmpdir.as_cwd():
+ with log_output('foo.txt') as logger:
+ with logger.force_echo():
+ echo('echo')
+ print('logged')
- assert capfd.readouterr() == ('echo\n', '')
+ assert capfd.readouterr() == ('echo\n', '')
- with open('foo.txt') as f:
- assert f.read() == 'logged\n'
+ with open('foo.txt') as f:
+ assert f.read() == 'logged\n'