Package test_suite :: Package unit_tests :: Package _prompt :: Module data_types
[hide private]
[frames] | no frames]

Source Code for Module test_suite.unit_tests._prompt.data_types

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2007-2013 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 numpy import int8, int16, int32, int64, float32, float64, zeros 
 24   
 25  # relax module imports. 
 26  from lib.io import DummyFileObject 
 27   
28 -class Container:
29 """A class to act as a container.""" 30 31 pass
32 33
34 -def dummy_fn():
35 """A dummy function for testing data types.""" 36 37 pass
38
39 -def dummy_fn2():
40 """A second dummy function for testing data types.""" 41 42 return "Hello"
43 44 45 # Create the array. 46 DATA_TYPES = [] 47 """An array of many different Python objects for testing the correct behaviour of user function args.""" 48 49 50 # Binaries. 51 DATA_TYPES.append(['bin', 0]) 52 DATA_TYPES.append(['bin', 1]) 53 54 # Booleans. 55 DATA_TYPES.append(['bool', True]) 56 DATA_TYPES.append(['bool', False]) 57 58 # Class objects. 59 DATA_TYPES.append(['class obj', Container()]) 60 61 # Classes. 62 DATA_TYPES.append(['class', Container]) 63 64 # Dictionaries. 65 DATA_TYPES.append(['dict', {}]) 66 DATA_TYPES.append(['dict', {'a': 0, 'b': 1}]) 67 68 # Integers. 69 DATA_TYPES.append(['int', 2]) 70 DATA_TYPES.append(['int', 10]) 71 DATA_TYPES.append(['int', -10]) 72 73 # Numpy ints. 74 DATA_TYPES.append(['int', zeros(2, int8)[0]]) 75 DATA_TYPES.append(['int', zeros(2, int16)[0]]) 76 DATA_TYPES.append(['int', zeros(2, int32)[0]]) 77 DATA_TYPES.append(['int', zeros(2, int64)[0]]) 78 79 # File descriptor. 80 DATA_TYPES.append(['file', DummyFileObject()]) 81 82 # Floats. 83 DATA_TYPES.append(['float', 0.0]) 84 DATA_TYPES.append(['float', 1e-7]) 85 DATA_TYPES.append(['float', 1000000.0]) 86 87 # Numpy floats. 88 DATA_TYPES.append(['float', zeros(2, float32)[0]]) 89 DATA_TYPES.append(['float', zeros(2, float64)[0]]) 90 91 # Functions. 92 DATA_TYPES.append(['function', dummy_fn]) 93 DATA_TYPES.append(['function', dummy_fn2]) 94 95 # Lists. 96 DATA_TYPES.append(['list', []]) 97 DATA_TYPES.append(['none list', [None, None]]) 98 99 # List of integers. 100 DATA_TYPES.append(['int list', [-1, 0, 1]]) 101 DATA_TYPES.append(['int list', [zeros(2, int32)[0]]]) 102 103 # List of floats. 104 DATA_TYPES.append(['float list', [-1., 0., 1.]]) 105 DATA_TYPES.append(['float list', [zeros(2, float64)[0]]]) 106 107 # List of numbers. 108 DATA_TYPES.append(['number list', [-1., 0, 1.]]) 109 110 # Lists of strings. 111 DATA_TYPES.append(['str list', ['a']]) 112 DATA_TYPES.append(['str list', ['a', 'asldfjk']]) 113 114 # None. 115 DATA_TYPES.append(['None', None]) 116 117 # Strings. 118 DATA_TYPES.append(['str', 'a']) 119 DATA_TYPES.append(['str', '10']) 120 121 # Tuple. 122 DATA_TYPES.append(['tuple', (None, None)]) 123 124 # Tuples of floats. 125 DATA_TYPES.append(['float tuple', (0.0,)]) 126 DATA_TYPES.append(['float tuple', (0.0, 0.0)]) 127 DATA_TYPES.append(['float tuple', (0.0, 0.0, 0.0)]) 128 DATA_TYPES.append(['float tuple', (0.0, 0.0, 0.0, 0.0)]) 129 DATA_TYPES.append(['float tuple', (0.0, 0.0, 0.0, 0.0, 0.0)]) 130 DATA_TYPES.append(['float tuple', (0.0, 0.0, 0.0, 0.0, 0.0, 0.0)]) 131 DATA_TYPES.append(['float tuple', (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)]) 132 133 # Tuples of strings. 134 DATA_TYPES.append(['str tuple', ('a',)]) 135 DATA_TYPES.append(['str tuple', ('a', 'b')]) 136 DATA_TYPES.append(['str tuple', ('a', 'b', 'c')]) 137