Passed
Push — master ( 6999df...2ddfa2 )
by Stefan
05:27
created

test_level2_pp_cli._gentestfile()   A

Complexity

Conditions 1

Size

Total Lines 16
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 14
nop 2
dl 0
loc 16
rs 9.7
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
# vim:fileencoding=utf-8
3
#
4
# Copyright (c) 2019 Stefan Bender
5
#
6
# This module is part of sciapy.
7
# sciapy is free software: you can redistribute it or modify
8
# it under the terms of the GNU General Public License as published
9
# by the Free Software Foundation, version 2.
10
# See accompanying LICENSE file or http://www.gnu.org/licenses/gpl-2.0.html.
11
"""SCIAMACHY level 2 post processing command line interface tests
12
13
Test functions to assure that the command line interface works in
14
most of the cases.
15
"""
16
import os
17
import sys
18
from subprocess import Popen
19
20
import pytest
21
from nccmpx import (ncallclose, nccmpattrs, ncequal, ncidentical)
22
try:
23
	import netCDF4
24
	NC_EXT = ".nc"
25
	NC_FMT = "-4"
26
	CDL_EXT = ".cdl"
27
except ImportError:
28
	NC_EXT = ".nc3"
29
	NC_FMT = "-3"
30
	CDL_EXT = ".cdl3"
31
32
DATADIR = os.path.join(".", "tests", "data")
33
IFILE1 = os.path.join(DATADIR, "test_v{0}" + NC_EXT)
34
IFILE2 = os.path.join(DATADIR, "test_v{0}x" + NC_EXT)
35
36
37
def _gentestfile(tfile, tmpdir):
38
	tpath = os.path.join(
39
		tmpdir,
40
		os.path.basename(tfile)
41
	)
42
	p = Popen([
43
		"ncgen",
44
		NC_FMT,
45
		"-o",
46
		tpath,
47
		tfile[:-len(NC_EXT)] + CDL_EXT,
48
	])
49
	p.communicate()
50
	p.wait()
51
	assert p.returncode == 0
52
	return tpath
53
54
55
def test_pp_help():
56
	p = Popen(["scia_post_process_l2.py", "-h"])
57
	p.communicate()
58
	p.wait()
59
	assert p.returncode == 0
60
61
62 View Code Duplication
@pytest.mark.xfail(
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
63
	sys.version_info[:2] == (3, 4),
64
	reason="netcdf file attributes don't work with Python 3.4 compatible xarray.",
65
)
66
@pytest.mark.parametrize("revision", ["2.1", "2.2"])
67
def test_pp_netcdf(revision, tmpdir):
68
	ifile = _gentestfile(IFILE1.format(revision), tmpdir)
69
	ofile = os.path.join(tmpdir, "test_v{0}_t.nc".format(revision))
70
	p = Popen([
71
		"scia_post_process_l2.py",
72
		"-A", "The Dude",
73
		"-M", "2010-02",
74
		"-R", revision,
75
		"-p", os.path.join(DATADIR, "l2"),
76
		"-s", os.path.join(DATADIR, "l1c"),
77
		"--mlt",
78
		ofile,
79
	])
80
	p.communicate()
81
	p.wait()
82
	assert p.returncode == 0
83
	ncallclose(ifile, ofile)
84
	nccmpattrs(ifile, ofile, ignore=["creation_time"])
85
86
87 View Code Duplication
@pytest.mark.xfail(
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
88
	sys.version_info[:2] == (3, 4),
89
	reason="netcdf file attributes don't work with Python 3.4 compatible xarray.",
90
)
91
@pytest.mark.parametrize("revision", ["2.1", "2.2"])
92
def test_pp_xarray(revision, tmpdir):
93
	ifile = _gentestfile(IFILE2.format(revision), tmpdir)
94
	ofile = os.path.join(tmpdir, "test_v{0}x_t.nc".format(revision))
95
	p = Popen([
96
		"scia_post_process_l2.py",
97
		"-A", "The Dude",
98
		"-M", "2010-02",
99
		"-R", revision,
100
		"-p", os.path.join(DATADIR, "l2"),
101
		"-s", os.path.join(DATADIR, "l1c"),
102
		"--mlt",
103
		"-X",
104
		ofile,
105
	])
106
	p.communicate()
107
	p.wait()
108
	assert p.returncode == 0
109
	ncallclose(ifile, ofile)
110
	nccmpattrs(ifile, ofile, ignore=["creation_time"])
111