Skip to content

Commit

Permalink
Merge pull request #39 from Ichimonji10/classmethod
Browse files Browse the repository at this point in the history
Do not instantiate FauxFactory
  • Loading branch information
omaciel committed Sep 18, 2014
2 parents 0f9d8ce + 127c582 commit 3927cd9
Show file tree
Hide file tree
Showing 14 changed files with 163 additions and 269 deletions.
10 changes: 1 addition & 9 deletions tests/test_booleans.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ class TestBooleans(unittest.TestCase):
Test boolean generator
"""

@classmethod
def setUpClass(cls):
"""
Instantiate our factory object
"""

cls.factory = FauxFactory()

def test_generate_boolean_1(self):
"""
@Test: Create a random boolean value
Expand All @@ -30,6 +22,6 @@ def test_generate_boolean_1(self):
"""

for turn in range(100):
result = self.factory.generate_boolean()
result = FauxFactory.generate_boolean()
self.assertIsInstance(result, bool,
"A valid boolean value was not generated.")
34 changes: 13 additions & 21 deletions tests/test_choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ class TestChoices(unittest.TestCase):
Test choices generator
"""

@classmethod
def setUpClass(cls):
"""
Instantiate our factory object
"""

cls.factory = FauxFactory()

def test_generate_choice_1(self):
"""
@Test: Select a random value from integer values
Expand All @@ -33,7 +25,7 @@ def test_generate_choice_1(self):
choices = range(5)

for turn in range(10):
result = self.factory.generate_choice(choices)
result = FauxFactory.generate_choice(choices)
self.assertIn(
result,
choices,
Expand All @@ -49,7 +41,7 @@ def test_generate_choice_2(self):
choices = string.ascii_letters + string.digits

for turn in range(10):
result = self.factory.generate_choice(choices)
result = FauxFactory.generate_choice(choices)
self.assertIn(
result,
choices,
Expand All @@ -65,7 +57,7 @@ def test_generate_choice_3(self):
choices = [1, ]

for turn in range(10):
result = self.factory.generate_choice(choices)
result = FauxFactory.generate_choice(choices)
self.assertEqual(
result,
choices[0],
Expand All @@ -81,7 +73,7 @@ def test_generate_choice_4(self):
choices = [1, 2, 3, 9, 10, 11, 100, 101, 102]

for turn in range(10):
result = self.factory.generate_choice(choices)
result = FauxFactory.generate_choice(choices)
self.assertIn(
result,
choices,
Expand All @@ -97,7 +89,7 @@ def test_generate_choice_5(self):
choices = (1, )

for turn in range(10):
result = self.factory.generate_choice(choices)
result = FauxFactory.generate_choice(choices)
self.assertEqual(
result,
choices[0],
Expand All @@ -113,7 +105,7 @@ def test_generate_choice_6(self):
choices = (1, 2, 3, 9, 10, 11, 100, 101, 102, )

for turn in range(10):
result = self.factory.generate_choice(choices)
result = FauxFactory.generate_choice(choices)
self.assertIn(
result,
choices,
Expand All @@ -129,7 +121,7 @@ def test_generate_choice_7(self):
choices = []

with self.assertRaises(ValueError):
self.factory.generate_choice(choices)
FauxFactory.generate_choice(choices)

def test_generate_choice_8(self):
"""
Expand All @@ -141,7 +133,7 @@ def test_generate_choice_8(self):
choices = ()

with self.assertRaises(ValueError):
self.factory.generate_choice(choices)
FauxFactory.generate_choice(choices)

def test_generate_choice_9(self):
"""
Expand All @@ -153,7 +145,7 @@ def test_generate_choice_9(self):
choices = {}

with self.assertRaises(ValueError):
self.factory.generate_choice(choices)
FauxFactory.generate_choice(choices)

def test_generate_choice_10(self):
"""
Expand All @@ -165,7 +157,7 @@ def test_generate_choice_10(self):
choices = {'Name': 'Bob', 'Age': 39}

with self.assertRaises(ValueError):
self.factory.generate_choice(choices)
FauxFactory.generate_choice(choices)

def test_generate_choice_11(self):
"""
Expand All @@ -181,7 +173,7 @@ def test_generate_choice_11(self):
]

for turn in range(10):
result = self.factory.generate_choice(choices)
result = FauxFactory.generate_choice(choices)
self.assertIn(
result,
choices,
Expand All @@ -197,7 +189,7 @@ def test_generate_choice_12(self):
choices = ['green', 'yellow', 'blue' 'white']

for turn in range(10):
result = self.factory.generate_choice(choices)
result = FauxFactory.generate_choice(choices)
self.assertIn(
result,
choices,
Expand All @@ -213,4 +205,4 @@ def test_generate_choice_13(self):
choices = None

with self.assertRaises(ValueError):
self.factory.generate_choice(choices)
FauxFactory.generate_choice(choices)
36 changes: 14 additions & 22 deletions tests/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,13 @@ class TestDates(unittest.TestCase):
Test date generator
"""

@classmethod
def setUpClass(cls):
"""
Instantiate our factory object
"""

cls.factory = FauxFactory()

def test_generate_date_1(self):
"""
@Test: Create a date with no arguments
@Feature: Date Generator
@Assert: Date is created with random values.
"""
result = self.factory.generate_date()
result = FauxFactory.generate_date()
self.assertTrue(
isinstance(result, datetime.date),
"Data is not instance of datetime.date.")
Expand All @@ -48,7 +40,7 @@ def test_generate_date_2(self):
min_date = today - datetime.timedelta(5)

for turn in range(10):
result = self.factory.generate_date(min_date=min_date)
result = FauxFactory.generate_date(min_date=min_date)
self.assertTrue(result >= min_date)

def test_generate_date_3(self):
Expand All @@ -64,7 +56,7 @@ def test_generate_date_3(self):
max_date = today + datetime.timedelta(5)

for turn in range(10):
result = self.factory.generate_date(max_date=max_date)
result = FauxFactory.generate_date(max_date=max_date)
self.assertTrue(result <= max_date)

def test_generate_date_4(self):
Expand All @@ -82,7 +74,7 @@ def test_generate_date_4(self):
max_date = today + datetime.timedelta(5)

for turn in range(10):
result = self.factory.generate_date(
result = FauxFactory.generate_date(
min_date=min_date,
max_date=max_date
)
Expand All @@ -103,7 +95,7 @@ def test_generate_date_5(self):
max_date = min_date + datetime.timedelta(365 * 1)

for turn in range(20):
result = self.factory.generate_date(
result = FauxFactory.generate_date(
min_date=None,
max_date=max_date
)
Expand All @@ -124,7 +116,7 @@ def test_generate_date_6(self):
min_date = max_date - datetime.timedelta(365 * 1)

for turn in range(20):
result = self.factory.generate_date(
result = FauxFactory.generate_date(
min_date=min_date,
max_date=None
)
Expand All @@ -146,7 +138,7 @@ def test_generate_date_7(self):
datetime.timedelta(365 * MAX_YEARS))

for turn in range(20):
result = self.factory.generate_date(
result = FauxFactory.generate_date(
min_date=min_date,
max_date=max_date
)
Expand All @@ -161,7 +153,7 @@ def test_generate_date_8(self):
"""

with self.assertRaises(ValueError):
self.factory.generate_date(
FauxFactory.generate_date(
min_date='',
max_date=''
)
Expand All @@ -174,7 +166,7 @@ def test_generate_date_9(self):
"""

with self.assertRaises(ValueError):
self.factory.generate_date(
FauxFactory.generate_date(
min_date='abc',
max_date='def'
)
Expand All @@ -187,7 +179,7 @@ def test_generate_date_10(self):
"""

with self.assertRaises(ValueError):
self.factory.generate_date(
FauxFactory.generate_date(
min_date=1,
max_date=1
)
Expand All @@ -200,7 +192,7 @@ def test_generate_date_11(self):
"""

with self.assertRaises(ValueError):
self.factory.generate_date(
FauxFactory.generate_date(
min_date=(1,),
max_date=(2, 3, 4)
)
Expand All @@ -213,7 +205,7 @@ def test_generate_date_12(self):
"""

with self.assertRaises(ValueError):
self.factory.generate_date(
FauxFactory.generate_date(
min_date=['a', 'b'],
max_date=['c', 'd', 'e']
)
Expand All @@ -231,7 +223,7 @@ def test_generate_date_13(self):
min_date = today + datetime.timedelta(5)

with self.assertRaises(AssertionError):
self.factory.generate_date(
FauxFactory.generate_date(
min_date=min_date,
max_date=today
)
Expand All @@ -244,7 +236,7 @@ def test_generate_date_14(self):
"""

with self.assertRaises(ValueError):
self.factory.generate_date(
FauxFactory.generate_date(
min_date=datetime.date.today(),
max_date='foo'
)
Loading

0 comments on commit 3927cd9

Please sign in to comment.