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