Skip to content

Commit

Permalink
#1 add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
boylegu committed Jan 5, 2016
1 parent 352decf commit d17f52a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
5 changes: 4 additions & 1 deletion regal/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ def __init__(self, version_host, combine=None, schedule=None):
self.combine = 1 if not combine else combine

def __add_info(self):
version_group = [(version, [hostname]) for version, hostname in self.host_version.iteritems()]
try:
version_group = [(version, [hostname]) for version, hostname in self.host_version.iteritems()]
except:
raise AttributeError("ERROR! The information is wrong")
return version_group

def grouping(self, priority_name=None):
Expand Down
39 changes: 39 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from unittest import TestCase

from regal import BaseInfo


# Run Method: python -m unittest -v tests.py
class TestBaseInfoInitial(TestCase):
def test_empty_info(self):
ab = BaseInfo('', '', '')
with self.assertRaises(AttributeError):
ab.grouping()

def test_empty_info_version_host_isdict(self):
ab = BaseInfo({}, '', '')
self.assertIsNotNone(ab.grouping())

def test_info_errortype(self):
ab = BaseInfo({}, '1', 'sds')
self.assertIsNotNone(ab.grouping())


class TestGroupingResult(TestCase):
ver = {
'ver1': '1.1.1.1,2.2.2.2,3.3.3.3,4.4.4.4,5.1.1.1,6.2.2.2,7.3.3.3,8.4.4.4'}
combine_num = 4

def test_combine_num(self):
ab = BaseInfo(
self.ver,
self.combine_num
)
instance_combine_num = ab.grouping().result[0][1]
self.assertEqual(len(instance_combine_num[1:-1][0]), self.combine_num)

def test_schedule_num(self):
schedule_num = 2
ab = BaseInfo(self.ver, self.combine_num, schedule_num)
instance_combine_num = ab.grouping().result[0][1]
self.assertEqual(len(instance_combine_num[0][0].split(',')), schedule_num)

0 comments on commit d17f52a

Please sign in to comment.