source: nappy/trunk/nappy/unit_tests/test_na_file_template.txt @ 3529

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/nappy/trunk/nappy/unit_tests/test_na_file_template.txt@3529
Revision 3529, 1.7 KB checked in by astephen, 14 years ago (diff)

Added comparison to unit tests and set annotation=False in na_file.py write method.

Line 
1"""
2test_na_file_<FFI>.py
3====================
4
5Tests for the na_file_<FFI>.py module.
6
7"""
8
9# Import standard library modules
10import unittest
11import os
12import sys
13
14# Import local modules
15base_dir = os.environ.get("NAPPY_BASE_DIR", "../..")
16sys.path.append(base_dir)
17
18import nappy
19import nappy.utils.compare_na
20
21class NAFile<FFI>_TestCase(unittest.TestCase):
22
23    def setUp(self):
24        self.infile = os.path.join(base_dir, "data_files", "<FFI>.na")
25        self.outfile = os.path.join(base_dir, "test_outputs", "test_<FFI>.na")
26        self.out_csv = os.path.join(base_dir, "test_outputs", "test_<FFI>.csv")
27        self.fin = nappy.openNAFile(self.infile)
28        self.fin.readData()
29        self.na_dict = self.fin.getNADict()       
30
31    def test_read<FFI>(self):
32        "Tests reading FFI <FFI>."
33        self.assertEqual(type(self.na_dict), type({1:2}))
34
35    def test_write<FFI>(self):
36        "Tests writing FFI <FFI>."
37        fobj = nappy.openNAFile(self.outfile, mode="w", na_dict=self.na_dict)           
38        fobj.write()
39        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile))
40
41    def test_writeAnnotatedCSV<FFI>(self):
42        "Tests conversion to NetCDF."
43        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict)
44        fobj.write(delimiter=",", float_format="%.2d", annotation=True)
45        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile))
46 
47    def test_compareFiles<FFI>(self):
48        "Tests comparison of written and original files for equivalence."
49        res = nappy.utils.compare_na.compNAFiles(self.infile, self.outfile)
50        self.assertEqual(res, True)
51       
52
53if __name__ ==  "__main__":
54
55    unittest.main()
56
57
Note: See TracBrowser for help on using the repository browser.