Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

from __future__ import with_statement 

import unittest 

import numpy as np 

import lsst.utils.tests 

from lsst.sims.utils.CodeUtilities import _validate_inputs 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

class CodeUtilsTest(unittest.TestCase): 

 

def test_validate_inputs(self): 

""" 

test that _validate_inputs returns expected values 

""" 

 

# test that it correctly identifies numpy array inputs 

self.assertTrue(_validate_inputs([np.array([1, 2]), 

np.array([3, 4])], 

['a', 'b'], 

'dummy_method')) 

 

# test that it correctly identifies inputs that are numbers 

self.assertFalse(_validate_inputs([1, 2, 3], ['a', 'b', 'c'], 'dummy')) 

 

# test that the correct exception is raised when you pass in 

# a number a numpy array 

with self.assertRaises(RuntimeError) as ee: 

_validate_inputs([1, np.array([2, 3])], ['a', 'b'], 'dummy') 

 

self.assertIn("and the same type", ee.exception.args[0]) 

 

# test that the correct exception is raised when you pass in 

# numpy arrays of different length 

with self.assertRaises(RuntimeError) as ee: 

_validate_inputs([np.array([1, 2]), np.array([1, 2, 3])], 

['a', 'b'], 'dummy') 

 

self.assertIn("same length", ee.exception.args[0]) 

 

# test that an exception is raised if lists (rather than numpy 

# arrays) are passed in 

with self.assertRaises(RuntimeError) as ee: 

_validate_inputs([[1, 2], [3, 4]], ['a', 'b'], 'dummy') 

 

self.assertIn("either a number or a numpy array", 

ee.exception.args[0]) 

 

 

class MemoryTestClass(lsst.utils.tests.MemoryTestCase): 

pass 

 

55 ↛ 56line 55 didn't jump to line 56, because the condition on line 55 was never trueif __name__ == "__main__": 

lsst.utils.tests.init() 

unittest.main()