def test_read_runner_nofiles(capsys): '''Test that the script deals with no files provided as expected.''' # run the relevant script method (runner()) read.runner(None, DummyArgs(), []) # capture the output and check that no output is generated stdout, _ = capsys.readouterr() assert stdout == ""
def test_read_runner_file(capsys, tmpdir): '''Test that the script deals with one file as expected.''' my_file = tmpdir.mkdir("sub").join("hello.f90") my_file.write("program hello\nend program hello\n") read.runner(None, DummyReadArgs(), [str(my_file)]) stdout, _ = capsys.readouterr() assert "line #1'program hello'" in stdout assert "line #2'end program hello'" in stdout
def test_read_runner_no_show(tmpdir): '''Test that the script raises an exception if the task argument != "show" as that is the only option currently supported. ''' my_file = tmpdir.mkdir("sub").join("hello.f90") my_file.write("program hello\nend program hello\n") with pytest.raises(NotImplementedError) as excinfo: read.runner(None, DummyReadArgs("invalid"), [str(my_file)]) assert ("The task option ''invalid'' is invalid. Currently only 'show' " "is supported.") in str(excinfo.value)
def test_read_runner_files(capsys, tmpdir): '''Test that the script deals with multiple files as expected.''' my_file1 = tmpdir.mkdir("sub1").join("hello1.f90") my_file1.write("program hello1\nend program hello1\n") my_file2 = tmpdir.mkdir("sub2").join("hello2.f90") my_file2.write("program hello2\nend program hello2\n") read.runner(None, DummyReadArgs(), [str(my_file1), str(my_file2)]) stdout, _ = capsys.readouterr() assert "line #1'program hello1'" in stdout assert "line #2'end program hello1'" in stdout assert "line #1'program hello2'" in stdout assert "line #2'end program hello2'" in stdout