Ejemplo n.º 1
0
def test_check_attribute_pairs_have_equal_length():
    """test for check_attribute_pairs_have_equal_length function"""
    #check_attribute_pairs_have_equal_length(obj, attributes=[])

    a = EmptyClass()

    a.a = None
    a.b = [7, 8]
    a.c = [8]
    a.d = [6, 7]
    a.e = 8

    #    assert_raises(ValueError, check_attribute_pairs_have_equal_length, a,
    #                  attributes=[['a','b']])
    assert_raises(ValueError,
                  check_attribute_pairs_have_equal_length,
                  a,
                  attributes=[['b', 'c']])
    assert_raises(TypeError,
                  check_attribute_pairs_have_equal_length,
                  a,
                  attributes=[['b', 'e']])

    assert_equal(
        check_attribute_pairs_have_equal_length(a, attributes=[['b', 'd']]),
        None)
Ejemplo n.º 2
0
def test_inject():
    em, app = _setup()
    em.enable_xhr(app)
    em.enable_injection(app)
    em.add_injectable(InjectableClass)

    with app.test_client() as c:
        r = c.get('/inject/joe-slug')
        assert_in('joe-slug', r.data)

        r = c.get('/inject-as-arg/joe-slug')
        assert_in('joe-slug', r.data)

        with assert_raises(RuntimeError):
            r = c.get('/inject-non-injectable/here-comes-an-error')

        em.add_injectable(NonInjectableClass)

        with assert_raises(RuntimeError):
            r = c.get('/inject-non-injectable/still-going-to-fail')

        with assert_raises(AttributeError):
            r = c.get('/inject-skip-by-default')

        r = c.get('/inject-list-denoting/apples')
        assert_equals(r.status_code, 200)
    def test_force_strictly_increasing(self):
        """test force_strictly_increasing"""
        x, y = force_strictly_increasing(self.two_ramps['x'], eps=0.01)
        ok_(np.all(x == np.array(self.two_ramps['x'])))

        assert_raises(ValueError, force_strictly_increasing,
                      self.switch_back['x'])

        x, y = force_strictly_increasing(self.two_ramps_two_steps['x'],
                                         self.two_ramps_two_steps['y'],
                                         keep_end_points=True,
                                         eps=0.01)
        ok_(np.allclose(x, np.array([0, 0.38, 0.4, 1, 2.5, 2.99, 3])))
        ok_(np.allclose(y, np.array(self.two_ramps_two_steps['y'])))

        x, y = force_strictly_increasing(self.two_ramps_two_steps['x'],
                                         self.two_ramps_two_steps['y'],
                                         keep_end_points=False,
                                         eps=0.01)
        ok_(np.allclose(x, np.array([0, 0.4, 0.41, 1, 2.5, 3, 3.02])))

        x, y = force_strictly_increasing(self.two_ramps_two_steps_reverse['x'],
                                         self.two_ramps_two_steps_reverse['y'],
                                         keep_end_points=False,
                                         eps=0.01)
        ok_(np.allclose(x, np.array([-3, -2.99, -2.5, -1, -0.4, -0.38, 0])))
        ok_(np.allclose(y, np.array(self.two_ramps_two_steps['y'][::-1])))
Ejemplo n.º 4
0
def test_inject():
    em, app = _setup()
    em.enable_xhr(app)
    em.enable_injection(app)
    em.add_injectable(InjectableClass)

    with app.test_client() as c:
        r = c.get('/inject/joe-slug')
        assert_in('joe-slug', r.data)

        r = c.get('/inject-as-arg/joe-slug')
        assert_in('joe-slug', r.data)

        with assert_raises(RuntimeError):
            r = c.get('/inject-non-injectable/here-comes-an-error')

        em.add_injectable(NonInjectableClass)

        with assert_raises(RuntimeError):
            r = c.get('/inject-non-injectable/still-going-to-fail')

        with assert_raises(AttributeError):
            r = c.get('/inject-skip-by-default')

        r = c.get('/inject-list-denoting/apples')
        assert_equals(r.status_code, 200)
Ejemplo n.º 5
0
    def test_check_zero_or_all(self):
        a = InputFileLoaderCheckerSaver()
        a.a=4
        a.b=6
        a.c=None
        a._zero_or_all = ['a b c'.split()]

        assert_raises(ValueError, a.check_input_attributes)
Ejemplo n.º 6
0
def test_talbot_dps_fail():
    "test for Talbot numerical inverse Laplace with mpmath insufficient dps"

    a = Talbot(f=f1, n=200, shift=0.0, dps=None)
    #t=0 raise error:
    assert_raises(ValueError, a, 0)
    #single value of t:
    ok_(not mpallclose(a(1), mpmath.exp(mpmath.mpf('-1.0'))))
Ejemplo n.º 7
0
def  test_talbot_dps_fail():
    "test for Talbot numerical inverse Laplace with mpmath insufficient dps"

    a = Talbot(f=f1, n=200, shift=0.0, dps=None)
    #t=0 raise error:
    assert_raises(ValueError, a, 0)
    #single value of t:
    ok_(not mpallclose(a(1), mpmath.exp(mpmath.mpf('-1.0'))))
Ejemplo n.º 8
0
    def test_check_zero_or_all(self):
        a = InputFileLoaderCheckerSaver()
        a.a = 4
        a.b = 6
        a.c = None
        a._zero_or_all = ['a b c'.split()]

        assert_raises(ValueError, a.check_input_attributes)
Ejemplo n.º 9
0
 def test_multipe_kap(self):
     assert_raises(ValueError,
                   back_calc_drain_spacing_from_eta,
                   1,
                   't',
                   mu_constant,
                   0.05, [5, 6],
                   2,
                   muw=1)
Ejemplo n.º 10
0
 def test_n_falls_below_s(self):
     assert_raises(ValueError,
                   back_calc_drain_spacing_from_eta,
                   5,
                   't',
                   mu_constant,
                   0.05,
                   5,
                   2,
                   muw=1)
Ejemplo n.º 11
0
def  test_talbot_dps_precision():
    """test for Talbot numerical inverse Laplace with mpmath high precision"""

    a = Talbot(f=f1, n=200, shift=0.0, dps=95)
    #t=0 raise error:
    assert_raises(ValueError, a, 0)
    #single value of t:
    ok_(mpallclose(a(1),
                   mpmath.exp(mpmath.mpf('-1.0')),
                   atol=mpmath.mpf('1e-80'),
                   rtol=mpmath.mpf('1e-40') ))
 def test_force_non_decreasing(self):
     """test force_non_decreasing"""
     x, y = force_non_decreasing(self.two_ramps_two_steps['x'], self.two_ramps_two_steps['y'])                 
     ok_(np.all(x==np.array(self.two_ramps_two_steps['x'])))
     ok_(np.all(y==np.array(self.two_ramps_two_steps['y'])))
     
     assert_raises(ValueError, force_non_decreasing, self.switch_back['x'])
     
     x, y = force_non_decreasing(self.two_ramps_two_steps_reverse['x'], self.two_ramps_two_steps_reverse['y'])                 
     ok_(np.all(x==np.array([-3, -3, -2.5, -1, -0.4, -0.4, 0])))
     ok_(np.all(y==np.array(self.two_ramps_two_steps['y'][::-1])))        
Ejemplo n.º 13
0
def test_talbot_dps_precision():
    """test for Talbot numerical inverse Laplace with mpmath high precision"""

    a = Talbot(f=f1, n=200, shift=0.0, dps=95)
    #t=0 raise error:
    assert_raises(ValueError, a, 0)
    #single value of t:
    ok_(
        mpallclose(a(1),
                   mpmath.exp(mpmath.mpf('-1.0')),
                   atol=mpmath.mpf('1e-80'),
                   rtol=mpmath.mpf('1e-40')))
Ejemplo n.º 14
0
def test_rgb_shade():
    """some tests for rgb_shade"""
#    rgb_shade(rgb, factor=1, scaled=True)
    ok_(np.allclose(rgb_shade((0.4, 0.8, 0.2)), (0.4, 0.8, 0.2)))

    ok_(np.allclose(rgb_shade((0.4, 0.8, 0.2), factor=0.5),
                        (0.2, 0.4, 0.1)))
    ok_(np.allclose(rgb_shade((0.4, 0.8, 0.2, 0.8), factor=0.5),
                        (0.2, 0.4, 0.1,0.8)))
#    assert_equal(rgb_shade((0.4, 0.8, 0.2)), (0.4, 0.8, 0.2))

    assert_raises(ValueError, rgb_shade,(0.5,0.5,0.5),factor=1.5)
    assert_raises(ValueError, rgb_shade,(0.5,0.5,0.5),factor=-0.5)
Ejemplo n.º 15
0
def  test_talbot():
    """test for Talbot numerical inverse Laplace with mpmath"""

    a = Talbot(f=f1, n=24, shift=0.0, dps=None)
    #t=0 raise error:
    assert_raises(ValueError, a, 0)
    #single value of t:
    ok_(mpallclose(a(1), mpmath.exp(mpmath.mpf('-1.0'))))

    #2 values of t:
    ans = np.array([mpmath.exp(mpmath.mpf('-1.0')),
                  mpmath.exp(mpmath.mpf('-2.0'))])
    ok_(mpallclose(a([1,2]),ans))
Ejemplo n.º 16
0
def test_rgb_shade():
    """some tests for rgb_shade"""
    #    rgb_shade(rgb, factor=1, scaled=True)
    ok_(np.allclose(rgb_shade((0.4, 0.8, 0.2)), (0.4, 0.8, 0.2)))

    ok_(np.allclose(rgb_shade((0.4, 0.8, 0.2), factor=0.5), (0.2, 0.4, 0.1)))
    ok_(
        np.allclose(rgb_shade((0.4, 0.8, 0.2, 0.8), factor=0.5),
                    (0.2, 0.4, 0.1, 0.8)))
    #    assert_equal(rgb_shade((0.4, 0.8, 0.2)), (0.4, 0.8, 0.2))

    assert_raises(ValueError, rgb_shade, (0.5, 0.5, 0.5), factor=1.5)
    assert_raises(ValueError, rgb_shade, (0.5, 0.5, 0.5), factor=-0.5)
    def test_force_non_decreasing(self):
        """test force_non_decreasing"""
        x, y = force_non_decreasing(self.two_ramps_two_steps['x'],
                                    self.two_ramps_two_steps['y'])
        ok_(np.all(x == np.array(self.two_ramps_two_steps['x'])))
        ok_(np.all(y == np.array(self.two_ramps_two_steps['y'])))

        assert_raises(ValueError, force_non_decreasing, self.switch_back['x'])

        x, y = force_non_decreasing(self.two_ramps_two_steps_reverse['x'],
                                    self.two_ramps_two_steps_reverse['y'])
        ok_(np.all(x == np.array([-3, -3, -2.5, -1, -0.4, -0.4, 0])))
        ok_(np.all(y == np.array(self.two_ramps_two_steps['y'][::-1])))
Ejemplo n.º 18
0
def test_talbot():
    """test for Talbot numerical inverse Laplace with mpmath"""

    a = Talbot(f=f1, n=24, shift=0.0, dps=None)
    #t=0 raise error:
    assert_raises(ValueError, a, 0)
    #single value of t:
    ok_(mpallclose(a(1), mpmath.exp(mpmath.mpf('-1.0'))))

    #2 values of t:
    ans = np.array(
        [mpmath.exp(mpmath.mpf('-1.0')),
         mpmath.exp(mpmath.mpf('-2.0'))])
    ok_(mpallclose(a([1, 2]), ans))
Ejemplo n.º 19
0
def test_make_module_from_text():
    """test for make_module_from_text function"""
    #make_module_from_text(reader)
    reader = textwrap.dedent("""\
        a = 2
        """)

    ok_(isinstance(make_module_from_text(reader), type(textwrap)))

    assert_equal(make_module_from_text(reader).a, 2)

    assert_raises(SyntaxError,make_module_from_text,
                  reader,
                  syntax_checker=SyntaxChecker())
Ejemplo n.º 20
0
def test_make_module_from_text():
    """test for make_module_from_text function"""
    #make_module_from_text(reader)
    reader = textwrap.dedent("""\
        a = 2
        """)

    ok_(isinstance(make_module_from_text(reader), type(textwrap)))

    assert_equal(make_module_from_text(reader).a, 2)

    assert_raises(SyntaxError,make_module_from_text,
                  reader,
                  syntax_checker=SyntaxChecker())
Ejemplo n.º 21
0
def test_check_attribute_is_list():
    """test for check_attribute_is_list function"""
    #check_attribute_is_list(obj, attributes=[], force_list=False)

    a = EmptyClass()

    a.a = 2
    a.b = 4
    a.c = [8]
    a.d = [6,7]

    assert_raises(ValueError, check_attribute_is_list, a, attributes=['a','b','c'], force_list=False)

    check_attribute_is_list(a, attributes=['a','b','c'], force_list=True)

    assert_equal([a.a,a.b,a.c,a.d], [[2],[4],[8], [6,7]])
Ejemplo n.º 22
0
def test_check_attribute_is_list():
    """test for check_attribute_is_list function"""
    #check_attribute_is_list(obj, attributes=[], force_list=False)

    a = EmptyClass()

    a.a = 2
    a.b = 4
    a.c = [8]
    a.d = [6,7]

    assert_raises(ValueError, check_attribute_is_list, a, attributes=['a','b','c'], force_list=False)

    check_attribute_is_list(a, attributes=['a','b','c'], force_list=True)

    assert_equal([a.a,a.b,a.c,a.d], [[2],[4],[8], [6,7]])
    def test_force_strictly_increasing(self):
        """test force_strictly_increasing"""
        x, y = force_strictly_increasing(self.two_ramps['x'], eps=0.01)                 
        ok_(np.all(x==np.array(self.two_ramps['x'])))
        
        assert_raises(ValueError, force_strictly_increasing, self.switch_back['x'])
        
        x, y = force_strictly_increasing(self.two_ramps_two_steps['x'], self.two_ramps_two_steps['y'], keep_end_points = True, eps=0.01)                 
        ok_(np.allclose(x, np.array([0,  0.38,   0.4,  1,  2.5,  2.99,  3])))
        ok_(np.allclose(y, np.array(self.two_ramps_two_steps['y'])))
        
        x, y = force_strictly_increasing(self.two_ramps_two_steps['x'], self.two_ramps_two_steps['y'], keep_end_points = False, eps=0.01)                 
        ok_(np.allclose(x, np.array([0,  0.4,   0.41,  1,  2.5,  3,  3.02])))

        x, y = force_strictly_increasing(self.two_ramps_two_steps_reverse['x'], self.two_ramps_two_steps_reverse['y'], keep_end_points = False, eps=0.01)                 
        ok_(np.allclose(x, np.array([-3, -2.99, -2.5, -1, -0.4, -0.38, 0])))
        ok_(np.allclose(y, np.array(self.two_ramps_two_steps['y'][::-1])))
Ejemplo n.º 24
0
def test_rgb_tint():
    """some tests for rgb_tint"""
#    rgb_tint(rgb, factor=1, scaled=True)
    ok_(np.allclose(rgb_tint((0.4, 0.8, 0.2)), (0.4, 0.8, 0.2)))

    ok_(np.allclose(rgb_tint((0.4, 0.8, 0.2), factor=0.5),
                        (0.7, 0.9, 0.6)))

#    assert_equal(rgb_tint((0.4, 0.8, 0.2)), (0.4, 0.8, 0.2))

    assert_raises(ValueError, rgb_tint,(0.5,0.5,0.5),factor=1.5)
    assert_raises(ValueError, rgb_tint,(0.5,0.5,0.5),factor=-0.5)

    ok_(np.allclose(rgb_tint((155, 205, 55), factor=0.5, scaled=False),
                        (205, 230, 155)))
    ok_(np.allclose(rgb_tint((155, 205, 55, 0.5), factor=0.5, scaled=False),
                        (205, 230, 155, 0.5)))
Ejemplo n.º 25
0
def test_rgb_tint():
    """some tests for rgb_tint"""
#    rgb_tint(rgb, factor=1, scaled=True)
    ok_(np.allclose(rgb_tint((0.4, 0.8, 0.2)), (0.4, 0.8, 0.2)))

    ok_(np.allclose(rgb_tint((0.4, 0.8, 0.2), factor=0.5),
                        (0.7, 0.9, 0.6)))

#    assert_equal(rgb_tint((0.4, 0.8, 0.2)), (0.4, 0.8, 0.2))

    assert_raises(ValueError, rgb_tint,(0.5,0.5,0.5),factor=1.5)
    assert_raises(ValueError, rgb_tint,(0.5,0.5,0.5),factor=-0.5)

    ok_(np.allclose(rgb_tint((155, 205, 55), factor=0.5, scaled=False),
                        (205, 230, 155)))
    ok_(np.allclose(rgb_tint((155, 205, 55, 0.5), factor=0.5, scaled=False),
                        (205, 230, 155, 0.5)))
Ejemplo n.º 26
0
def test_check_attribute_PolyLines_have_same_x_limits():
    """test for check_attribute_PolyLines_have_same_x_limits function"""
    #check_attribute_PolyLines_have_same_x_limits(obj, attributes=[])

    a = EmptyClass()

    a.a = None
    a.b = PolyLine([0,4],[4,5])
    a.c = [PolyLine([0,4],[6,3]), PolyLine([0,5],[6,3])]
    a.d = PolyLine([0,2,4], [3,2,4])

    assert_raises(ValueError, check_attribute_PolyLines_have_same_x_limits, a,
                  attributes=[['a','b','c','d']])

    assert_raises(ValueError, check_attribute_PolyLines_have_same_x_limits, a,
                  attributes=[['c']])

    assert_equal(check_attribute_PolyLines_have_same_x_limits(a,
                  attributes=[['a','b','d']]), None)
Ejemplo n.º 27
0
def test_check_attribute_PolyLines_have_same_x_limits():
    """test for check_attribute_PolyLines_have_same_x_limits function"""
    #check_attribute_PolyLines_have_same_x_limits(obj, attributes=[])

    a = EmptyClass()

    a.a = None
    a.b = PolyLine([0,4],[4,5])
    a.c = [PolyLine([0,4],[6,3]), PolyLine([0,5],[6,3])]
    a.d = PolyLine([0,2,4], [3,2,4])

    assert_raises(ValueError, check_attribute_PolyLines_have_same_x_limits, a,
                  attributes=[['a','b','c','d']])

    assert_raises(ValueError, check_attribute_PolyLines_have_same_x_limits, a,
                  attributes=[['c']])

    assert_equal(check_attribute_PolyLines_have_same_x_limits(a,
                  attributes=[['a','b','d']]), None)
Ejemplo n.º 28
0
def test_SyntaxChecker():
    """test for SytaxChecker class"""

    syntax_checker=SyntaxChecker(['ast','builtin','numpy','PolyLine'])


    assert_raises(SyntaxError, syntax_checker.visit,
                  ast.parse('import math', mode='exec'))

    assert_raises(SyntaxError, syntax_checker.visit,
                  ast.parse('from math import cos', mode='exec'))

    assert_raises(SyntaxError, syntax_checker.visit,
                  ast.parse('eval(44*2)', mode='exec'))

    assert_raises(SyntaxError, syntax_checker.visit,
                  ast.parse('exec("a=34")', mode='exec'))

    assert_raises(SyntaxError, syntax_checker.visit,
                  ast.parse("""[x for x in ().__class__.__bases__[0].__subclasses__()
           if x.__name__ == 'Popen'][0](['ls', '-la']).wait()""", mode='exec'))
Ejemplo n.º 29
0
def test_SyntaxChecker():
    """test for SytaxChecker class"""

    syntax_checker=SyntaxChecker(['ast','builtin','numpy','PolyLine'])


    assert_raises(SyntaxError, syntax_checker.visit,
                  ast.parse('import math', mode='exec'))

    assert_raises(SyntaxError, syntax_checker.visit,
                  ast.parse('from math import cos', mode='exec'))

    assert_raises(SyntaxError, syntax_checker.visit,
                  ast.parse('eval(44*2)', mode='exec'))

    assert_raises(SyntaxError, syntax_checker.visit,
                  ast.parse('exec("a=34")', mode='exec'))

    assert_raises(SyntaxError, syntax_checker.visit,
                  ast.parse("""[x for x in ().__class__.__bases__[0].__subclasses__()
           if x.__name__ == 'Popen'][0](['ls', '-la']).wait()""", mode='exec'))
Ejemplo n.º 30
0
def test_check_attribute_pairs_have_equal_length():
    """test for check_attribute_pairs_have_equal_length function"""
    #check_attribute_pairs_have_equal_length(obj, attributes=[])

    a = EmptyClass()

    a.a = None
    a.b = [7, 8]
    a.c = [8]
    a.d = [6,7]
    a.e = 8

#    assert_raises(ValueError, check_attribute_pairs_have_equal_length, a,
#                  attributes=[['a','b']])
    assert_raises(ValueError, check_attribute_pairs_have_equal_length, a,
                  attributes=[['b','c']])
    assert_raises(TypeError, check_attribute_pairs_have_equal_length, a,
                  attributes=[['b','e']])

    assert_equal(check_attribute_pairs_have_equal_length(a,
                  attributes=[['b','d']]), None)
Ejemplo n.º 31
0
def test_or():
	string_validator = konval.types.IsType(str)
	success_validator = konval.Konvalidator()

	or_validator = konval.Or((string_validator, success_validator))

	numerical_value = 123

	assert_true(or_validator.validate(numerical_value))
	assert_equal(or_validator.validate(numerical_value), numerical_value)

	size_validator = konval.numbers.Minimum(200)
	or_validator = konval.Or((string_validator, size_validator))

	with assert_raises(konval.KonvalError):
		or_validator(numerical_value)
Ejemplo n.º 32
0
 def test_s_less_than_one(self):
     assert_raises(ValueError, u_piecewise_constant,[0.5,1,2], [1,1,1],1 )
Ejemplo n.º 33
0
 def test_s_increasing(self):
     assert_raises(ValueError, u_piecewise_constant,[1.5,1,2], [1,1,1],1 )
Ejemplo n.º 34
0
 def test_kap_less_than_zero(self):
     assert_raises(ValueError, u_piecewise_constant, [2, 4],[2,-1], 3)
Ejemplo n.º 35
0
 def test_si_less_than_1(self):
     assert_raises(ValueError, u_piecewise_constant, [2, 4],[2,1], 0.5)
Ejemplo n.º 36
0
 def test_s_greater_than_n(self):
     assert_raises(ValueError, mu_constant, 50, 100, 5)
Ejemplo n.º 37
0
 def test_s_less_than_one(self):
     assert_raises(ValueError, mu_constant, 50, 0.5, 5)
Ejemplo n.º 38
0
 def test_kap_less_than_zero(self):
     assert_raises(ValueError, u_parabolic, 50, 5, -0.5, 2)
Ejemplo n.º 39
0
 def test_s_less_than_one(self):
     assert_raises(ValueError, u_parabolic, 50, 0.5, 2, 2)
Ejemplo n.º 40
0
 def test_kap_less_than_zero(self):
     assert_raises(ValueError, u_piecewise_constant,[1.5,1.6,2], [-2,1,1],1)
Ejemplo n.º 41
0
 def test_s_n_unequal_len(self):
     assert_raises(ValueError, u_piecewise_constant, [2,4], [1],1)
Ejemplo n.º 42
0
 def test_s_greater_than_n(self):
     assert_raises(ValueError, u_parabolic, 50, 100, 2, 2)
Ejemplo n.º 43
0
 def test_kap_less_than_zero(self):
     assert_raises(ValueError, mu_constant, 50, 0.5, -5)
Ejemplo n.º 44
0
 def test_n_less_than_one(self):
     assert_raises(ValueError, u_piecewise_constant, [2, 0.5],[2,1], 1.5)
Ejemplo n.º 45
0
 def test_n_less_than_one(self):
     assert_raises(ValueError, u_piecewise_linear, [1, 2, 0.5],[2,1], 1.5)
Ejemplo n.º 46
0
 def test_si_greater_than_n(self):
     assert_raises(ValueError, u_piecewise_constant, [2, 4],[2,1], 5)