Package test_suite :: Package unit_tests :: Package _lib :: Module test_io
[hide private]
[frames] | no frames]

Source Code for Module test_suite.unit_tests._lib.test_io

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2007-2014 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Python module imports. 
 23  from os import sep 
 24  from unittest import TestCase 
 25   
 26  # relax module imports. 
 27  import lib.io 
 28   
 29   
30 -class Test_io(TestCase):
31 """Unit tests for the functions of the 'lib.io' module.""" 32 33
34 - def test_file_root(self):
35 """Test the lib.io.file_root() function with '/tmp/test.xyz'.""" 36 37 # The data. 38 file = '/tmp/test.xyz' 39 root = 'test' 40 41 # Check the function. 42 self.assertEqual(lib.io.file_root(file), root)
43 44
45 - def test_file_root2(self):
46 """Test the lib.io.file_root() function with '/tmp/test.xyz.gz'.""" 47 48 # The data. 49 file = '/tmp/test.xyz.gz' 50 root = 'test' 51 52 # Check the function. 53 self.assertEqual(lib.io.file_root(file), root)
54 55
56 - def test_get_file_path(self):
57 """Test for file paths which should remain unmodified by lib.io.get_file_path.""" 58 59 # Some file paths that shouldn't change. 60 file1 = 'test' 61 file2 = 'test'+sep+'aaa' 62 file3 = sep+'home'+sep+'test'+sep+'aaa' 63 64 # Check that nothing changes. 65 self.assertEqual(lib.io.get_file_path(file1), file1) 66 self.assertEqual(lib.io.get_file_path(file2), file2) 67 self.assertEqual(lib.io.get_file_path(file3), file3)
68 69
71 """The modification of file paths by lib.io.get_file_path when a directory is supplied.""" 72 73 # Some file paths. 74 file1 = 'test' 75 file2 = 'test'+sep+'aaa' 76 file3 = sep+'home'+sep+'test'+sep+'aaa' 77 78 # Some directories. 79 dir1 = sep+'usr' 80 dir2 = 'usr' 81 dir3 = sep+'usr' 82 83 # Check that nothing changes. 84 self.assertEqual(lib.io.get_file_path(file1, dir1), dir1+sep+file1) 85 self.assertEqual(lib.io.get_file_path(file2, dir2), dir2+sep+file2) 86 self.assertEqual(lib.io.get_file_path(file3, dir=dir3), dir3+sep+file3)
87 88
90 """The modification of file paths with '~', by lib.io.get_file_path.""" 91 92 # Some file paths. 93 file1 = '~'+sep+'test' 94 file2 = '~'+sep+'test'+sep+'aaa' 95 96 # Check that nothing changes. 97 self.assertNotEqual(lib.io.get_file_path(file1), file1) 98 self.assertNotEqual(lib.io.get_file_path(file2), file2)
99