source: nappy/trunk/tests/test_na_file_1001.py @ 7710

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/nappy/trunk/tests/test_na_file_1001.py@7710
Revision 7710, 2.7 KB checked in by astephen, 9 years ago (diff)

Added in right-stripping of any annotations included in curly braces "{...}" on the
end of any input lines in NASA Ames.

Line 
1"""
2test_na_file_1001.py
3====================
4
5Tests for the na_file_1001.py module.
6
7"""
8
9# Import standard library modules
10import unittest
11import os
12import sys
13
14import nappy
15import nappy.utils.compare_na
16
17here = os.path.dirname(__file__)
18data_files = os.path.join(here, '../data_files')
19test_outputs = os.path.join(here, '../test_outputs')
20
21class NAFile1001_TestCase(unittest.TestCase):
22
23    def setUp(self):
24        self.infile = os.path.join(data_files, "1001.na")
25        self.outfile = os.path.join(test_outputs, "test_1001.na")
26        self.out_csv = os.path.join(test_outputs, "test_1001.csv")
27        self.out_csv_annotated = os.path.join(test_outputs, "test_1001_annotated.csv")
28        self.fin = nappy.openNAFile(self.infile)
29        self.fin.readData()
30        self.na_dict = self.fin.getNADict()       
31
32    def test_read1001(self):
33        "Tests reading FFI 1001."
34        self.assertEqual(type(self.na_dict), type({1:2}))
35
36    def test_write1001(self):
37        "Tests writing FFI 1001."
38        fobj = nappy.openNAFile(self.outfile, mode="w", na_dict=self.na_dict)           
39        fobj.write()
40        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile))
41
42    def test_writeCSV1001(self):
43        "Tests conversion to CSV."
44        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict)
45        fobj.write(delimiter=",", float_format="%.6f")
46        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile))
47
48    def test_writeAnnotatedCSV1001(self):
49        "Tests conversion to Annotated CSV."
50        fobj = nappy.openNAFile(self.out_csv_annotated, mode="w", na_dict=self.na_dict)
51        fobj.write(delimiter=",", annotation=True)
52        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile))
53 
54    def test_compareFiles1001(self):
55        "Tests comparison of written and original files for equivalence."
56        res = nappy.utils.compare_na.compNAFiles(self.infile, self.outfile, approx_equal=True)
57        self.assertEqual(res, True)
58       
59    def test_compareNAToCSV1001(self):
60        "Tests comparison of original and CSV version written." 
61        res = nappy.utils.compare_na.compNAFiles(self.infile, self.out_csv, delimiter_2=",")
62        self.assertEqual(res, True)
63
64
65    def test_na1001CurlyWithCurlyBraces(self):
66        "Tests an input file with curly braces."
67        cb_file = os.path.join(data_files, "1001_cb.na")
68        fin = nappy.openNAFile(cb_file)
69        fin.readData()
70        na_dict = fin.getNADict()
71        foutname = os.path.join(test_outputs, "test_1001_cb_rewritten.na")
72        fobj = nappy.openNAFile(foutname, mode="w", na_dict=na_dict)
73        fobj.write()
74        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile))
75
76if __name__ ==  "__main__":
77
78    unittest.main()
79
80
Note: See TracBrowser for help on using the repository browser.