• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pysat / pysatModels / 7278065529

20 Dec 2023 04:20PM UTC coverage: 95.564% (-0.2%) from 95.796%
7278065529

Pull #129

github

web-flow
Merge branch 'develop' into clean_warning_update
Pull Request #129: Clean warning update

8 of 10 new or added lines in 5 files covered. (80.0%)

2 existing lines in 1 file now uncovered.

1508 of 1578 relevant lines covered (95.56%)

6.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.23
/pysatModels/tests/test_models.py
1
"""Unit and Integration Tests for each instrument module.
2

3
Note
4
----
5
Imports test methods from pysat.tests.instrument_test_class
6

7
"""
8

9
import datetime as dt
7✔
10
import os
7✔
11
import shutil
7✔
12
import sys
7✔
13
import tempfile
7✔
14

15
# Import the test classes from pysat
16
import pysat
7✔
17
from pysat.tests.classes import cls_instrument_library as clslib
7✔
18

19
import pysatModels
7✔
20

21
# Retrieve the lists of Model instruments and testing methods
22
instruments = clslib.InstLibTests.initialize_test_package(
7✔
23
    clslib.InstLibTests, inst_loc=pysatModels.models)
24

25

26
class TestModels(clslib.InstLibTests):
7✔
27
    """Main class for instrument tests.
28

29
    Note
30
    ----
31
    All standard tests, setup, and teardown inherited from the core pysat
32
    instrument test class.
33

34
    """
35

36

37
class TestSAMILoadMultipleDays(object):
7✔
38
    """Test SAMI load code for multiple days."""
39

40
    def setup_class(self):
7✔
41
        """Initialize the testing setup once before all tests are run."""
42
        # Make sure to use a temporary directory so that the user setup is not
43
        # altered
44

45
        # TODO(#100): remove if-statement when it is always triggered
46
        tkwargs = {}
7✔
47
        if sys.version_info.major >= 3 and sys.version_info.minor >= 10:
7✔
48
            tkwargs = {"ignore_cleanup_errors": True}
6✔
49
        self.tempdir = tempfile.TemporaryDirectory(**tkwargs)
7✔
50
        self.saved_path = pysat.params['data_dirs']
7✔
51
        pysat.params.data['data_dirs'] = [self.tempdir.name]
7✔
52

53
        # Assign the location of the model Instrument sub-modules
54
        self.inst_loc = pysatModels.models
7✔
55
        return
7✔
56

57
    def teardown_class(self):
7✔
58
        """Clean up downloaded files and parameters from tests."""
59

60
        pysat.params.data['data_dirs'] = self.saved_path
7✔
61

62
        # Remove the temporary directory
63
        # TODO(#100): Remove try/except when Python 3.10 is the lowest version
64
        try:
7✔
65
            self.tempdir.cleanup()
7✔
UNCOV
66
        except Exception:
×
UNCOV
67
            pass
×
68

69
        del self.inst_loc, self.saved_path, self.tempdir
7✔
70
        return
7✔
71

72
    def test_multidayload(self):
7✔
73
        """Test loading multiple SAMI days."""
74

75
        inst = pysat.Instrument(inst_module=self.inst_loc.sami2py_sami2,
7✔
76
                                tag='test')
77
        test_date = self.inst_loc.sami2py_sami2._test_dates['']['test']
7✔
78
        inst.download(test_date, test_date)
7✔
79
        dl_file = os.path.join(inst.files.data_path, inst.files.files.values[0])
7✔
80

81
        # Create a second file, increment day.
82
        tmpl = 'sami2py_output_{year:04d}-{month:02d}-{day:02d}.nc'
7✔
83
        date = test_date + dt.timedelta(days=1)
7✔
84
        cp_file = os.path.join(inst.files.data_path,
7✔
85
                               tmpl.format(year=date.year, month=date.month,
86
                                           day=date.day))
87
        shutil.copy(dl_file, cp_file)
7✔
88

89
        # Update file list
90
        inst.files.refresh()
7✔
91

92
        # Load both files
93
        end_date = date + dt.timedelta(days=1)
7✔
94
        inst.load(date=test_date, end_date=end_date)
7✔
95
        data_two_days = inst.data
7✔
96
        meta_two_days = inst.meta
7✔
97

98
        # Load original download file
99
        inst.load(date=test_date)
7✔
100
        data_one_days = inst.data
7✔
101
        meta_one_days = inst.meta
7✔
102

103
        # Confirm longer date range is longer data
104
        assert len(data_two_days['slt']) == 2 * len(data_one_days['slt'])
7✔
105

106
        # Confirm metadata came out ok
107
        assert meta_two_days == meta_one_days
7✔
108

109
        # Confirm time index information
110
        assert data_two_days.indexes['time'].is_monotonic_increasing
7✔
111
        assert data_two_days.indexes['time'][0] >= test_date
7✔
112
        assert data_two_days.indexes['time'][0] < date
7✔
113
        assert data_two_days.indexes['time'][-1] > date
7✔
114
        assert data_two_days.indexes['time'][-1] < end_date
7✔
115

116
        return
7✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc