source: nappy/branches/nappy-eggable/tests/test_na_file_2160.py @ 5072

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/nappy/branches/nappy-eggable/tests/test_na_file_2160.py@5072
Revision 5072, 2.2 KB checked in by spascoe, 11 years ago (diff)

Moved tests back out of the package hierarchy. They are now not
included in the egg but can be run from a checkout or a
distribution directory created with "easy_install -eb . nappy"

To run the tests do "python setup.py test" or "nosetests" from the
checkout.

RevLine 
[3414]1"""
2test_na_file_2160.py
3====================
4
5Tests for the na_file_2160.py module.
6
7"""
8
9# Import standard library modules
10import unittest
11import os
12import sys
13
14import nappy
[3529]15import nappy.utils.compare_na
[3414]16
[5072]17here = os.path.dirname(__file__)
18data_files = os.path.join(here, '../data_files')
19test_outputs = os.path.join(here, '../test_outputs')
20
[3414]21class NAFile2160_TestCase(unittest.TestCase):
22
23    def setUp(self):
[5072]24        self.infile = os.path.join(data_files, "2160.na")
25        self.outfile = os.path.join(test_outputs, "test_2160.na")
26        self.out_csv = os.path.join(test_outputs, "test_2160.csv")
27        self.out_csv_annotated = os.path.join(test_outputs, "test_2160_annotated.csv")
[3414]28        self.fin = nappy.openNAFile(self.infile)
29        self.fin.readData()
30        self.na_dict = self.fin.getNADict()       
31
32    def test_read2160(self):
33        "Tests reading FFI 2160."
34        self.assertEqual(type(self.na_dict), type({1:2}))
35
36    def test_write2160(self):
37        "Tests writing FFI 2160."
[3524]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))
[3414]41
[3625]42    def test_writeCSV2160(self):
43        "Tests conversion to CSV."
[3524]44        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict)
[3628]45        fobj.write(delimiter=",", float_format="%.6f")
[3524]46        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile))
[3625]47
48    def test_writeAnnotatedCSV2160(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))
[3524]53 
[3529]54    def test_compareFiles2160(self):
55        "Tests comparison of written and original files for equivalence."
[3625]56        res = nappy.utils.compare_na.compNAFiles(self.infile, self.outfile, approx_equal=True)
[3529]57        self.assertEqual(res, True)
[3625]58       
59    def test_compareNAToCSV2160(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)
[3524]63
[3625]64
[3414]65if __name__ ==  "__main__":
66
67    unittest.main()
68
69
Note: See TracBrowser for help on using the repository browser.