Skip to content

Commit

Permalink
removed random; fixed naming
Browse files Browse the repository at this point in the history
  • Loading branch information
anxolerd committed Aug 3, 2015
1 parent 037c5c1 commit ece9978
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions project/tests/test_type_enum.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
from unittest import TestCase
from project.lib.orm.types import TypeEnum
from random import randint
from enum import IntEnum

MAXINT = 2**4
MININT = -MAXINT - 1


class TestTypeEnumConversion(TestCase):

def setUp(self):
self.testing_intenum = IntEnum(
testing_intenum = IntEnum(
'Custom IntEnum',
{
'val_1': -1,
Expand All @@ -19,39 +15,31 @@ def setUp(self):
'val_4': -3,
},
)
self.testing_typeenum = TypeEnum(testing_intenum)

def test_positive_bind(self):
ie = self.testing_intenum
te = TypeEnum(ie)
for val in te._enum:
processed_type = te.process_bind_param(
val,
for good_value in self.testing_typeenum._enum:
processed_type = self.testing_typeenum.process_bind_param(
good_value,
dialect=None,
)
processed_int = te.process_bind_param(
val.value,
processed_int = self.testing_typeenum.process_bind_param(
good_value.value,
dialect=None,
)
self.assertEqual(processed_type, val.value)
self.assertEqual(processed_int, val.value)
self.assertEqual(processed_type, good_value.value)
self.assertEqual(processed_int, good_value.value)

def test_negative_bind(self):
ie = self.testing_intenum
te = TypeEnum(ie)
while True:
v = randint(MININT, MAXINT)
if v not in te._enum.__members__.values():
break
bad_value = 0
with self.assertRaises(TypeError):
te.process_bind_param(
v,
self.testing_typeenum.process_bind_param(
bad_value,
dialect=None,
)

def test_none_param(self):
ie = self.testing_intenum
te = TypeEnum(ie)
processed = te.process_bind_param(
processed = self.testing_typeenum.process_bind_param(
None,
dialect=None,
)
Expand Down

0 comments on commit ece9978

Please sign in to comment.