コード例 #1
0
 def test_60_title_iter(self):
     pi1 = PaperInfo('Paper1', '125')
     pi2 = PaperInfo('Paper2', '135')
     pi3 = PaperInfo('Paper3', '246')
     pi4 = PaperInfo('Paper4', '157')
     hi = HouseInfo(20, 'Road1', [pi1, pi2, pi3, pi4])
     self.assertTrue(isinstance(hi._titles, list))
コード例 #2
0
 def test_11_init(self):
     oi = [
         HouseInfo('Name', 'Road1', PaperInfo('Telegraph')),
         OrderInfo('Name', 'Road')
     ]
     with self.assertRaises(ValueError) as e:
         ri = RoundInfo(1, 'Round1', None, oi)
     self.assertEqual(e.exception.args[0],
                      "All elements must be 'OrderInfo' instances")
コード例 #3
0
'''
This is a test suite that will check if the _LimitList mixin class is correctly
operating on a specific object instance
'''

import unittest
from pydelivery.parser.parseround import _LimitList, HouseInfo, PaperInfo

pi = PaperInfo('Paper')
hi1 = HouseInfo(1, 'Road1', pi)
hi2 = HouseInfo('Name1', 'Road1', pi)
hi3 = HouseInfo('Name2', 'Road2', pi)

class Check_HouseList(_LimitList):
  def __init__(self, elems=None):
    super().__init__(HouseInfo, 'HouseInfo', elems)
    

class Test__LimitList(unittest.TestCase):
  def test_01_init(self):
    with self.assertRaises(TypeError) as e:
      ll = _LimitList()
    self.assertEqual(e.exception.args[0], "__init__() missing 2 required positional arguments: 'type_' and 'name'")
    
  def test_02_init(self):
    with self.assertRaises(TypeError) as e:
      ll = _LimitList(HouseInfo)
    self.assertEqual(e.exception.args[0], "__init__() missing 1 required positional argument: 'name'")
  
  def test_03_init(self):
    class Mock_Type:
コード例 #4
0
'''
This is the test suite for the PaperList object which provides a list with added
functionality to ensure that only elements inherited from PaperInfo can be stored.
'''

import unittest
from pydelivery.parser.parseround import PaperList, PaperInfo

# Define some instances of titles for use during testing
pi1 = PaperInfo('Paper1', '345')
pi2 = PaperInfo('Paper2', '16')
pi3 = PaperInfo('Paper3', '5')

class Test_PaperList(unittest.TestCase):
  def test_01_init(self):
    'Initialise no arguments'
    pl = PaperList()
    self.assertListEqual(pl, [])
    
  def test_02_init(self):
    'Initialise an empty list'
    pl = PaperList(None)
    self.assertListEqual(pl, [])
    
  def test_03_init(self):
    for chk in ([], ()):
      with self.subTest(chk=chk):
        with self.assertRaises(ValueError) as e:
          pl = PaperList(chk)
        self.assertEqual(e.exception.args[0], "Must provide a sequence with at least one 'PaperInfo' instance")
    
コード例 #5
0
'''
This is the test suite for the parseround module
'''

from pydelivery.parser.parseround import HouseInfo, PaperInfo, RoundInfo
import unittest

# Define some objects to be used within the tests
pi1 = PaperInfo('Paper1')
hi1 = HouseInfo(20, 'Road1', pi1)

class TestParseRound(unittest.TestCase):
  def test_01_add_house(self):
    '''Test the addition of a house to an empty round'''
    ri = RoundInfo(1, 'Round1')
    ri.add_house(hi1)
    self.assertEqual(ri._houses, [hi1])
コード例 #6
0
 def test_53_remove_days(self):
     pi = PaperInfo('Paper', '567')
     pi.remove_days('6')
     self.assertEqual(pi.days, {5, 7})
コード例 #7
0
 def test_52_add_days_fail(self):
     pi = PaperInfo('Paper', '6')
     pi.add_days('7')
     self.assertEqual(pi.days, {6, 7})
コード例 #8
0
 def test_02_init(self):
     with self.assertRaises(TypeError) as e:
         pi = PaperInfo(None)
     self.assertEqual(e.exception.args[0],
                      'Must provide a name for the information')
コード例 #9
0
 def test_01_add_days(self):
     pi = PaperInfo('Paper', '6')  # Add a paper delivered on Saturday
     pi.add_days('5')  # Add a paer to be delivered on Friday
     self.assertEqual(pi.days, {5, 6})
コード例 #10
0
 def test_08_daysequence(self):
     with self.assertRaises(ValueError) as e:
         pi = PaperInfo('Paper', '8')
     self.assertEqual(e.exception.args[0],
                      'Day sequence contains no valid days')
コード例 #11
0
 def test_07_daysequence(self):
     with self.assertRaises(KeyError) as e:
         pi = PaperInfo('Paper', {8})
     self.assertEqual(e.exception.args[0], 8)
コード例 #12
0
 def test_06_daysequence(self):
     pi = PaperInfo('Paper', None)
     with self.assertRaises(AttributeError) as e:
         pi.days = '8'
     self.assertEqual(e.exception.args[0], "can't set attribute")
コード例 #13
0
 def test_05_num_copies(self):
     pi = PaperInfo('Paper', None)
     with self.assertRaises(AttributeError) as e:
         pi.num_copies = -1
     self.assertEqual(e.exception.args[0], "can't set attribute")
     self.assertEqual(pi.num_copies, 1)
コード例 #14
0
 def test_04_init(self):
     pi = PaperInfo('Paper', None)
     self.assertEqual(pi._title, 'Paper')
     self.assertEqual(pi._days.days, {1, 2, 3, 4, 5, 6, 7})
     self.assertEqual(pi._copies, 1)
コード例 #15
0
 def test_03_init(self):
     with self.assertRaises(TypeError) as e:
         pi = PaperInfo('Paper', None, -2)
     self.assertEqual(e.exception.args[0],
                      'Must provide a positive number of copies')
コード例 #16
0
        with self.assertRaises(StopIteration):
            self.assertEqual(next(it), None)

    def test_24_eq(self):
        hi1 = HouseInfo('Old Barn', 'Hall Lane', None)
        hi2 = HouseInfo('Old Barn', 'Hall Lane', None)
        self.assertFalse(id(hi1) == id(hi2))
        self.assertTrue(hi1 == hi2)

    def test_25_eq(self):
        hi1 = HouseInfo('Old Barn', 'Hall Lane', None)
        self.assertFalse(hi1 == 'Old Barn')


# Provide a simple paper for the testing
Oper_Pi = PaperInfo('Paper1', '12345')


class TestHouseInfo_Oper(unittest.TestCase):
    'Test the operation of the HouseInfo class'

    def test_50_use_box(self):
        hi = HouseInfo(20, 'Road1', Oper_Pi, use_box=None)
        self.assertFalse(hasattr(hi, '_use_box'))

    def test_51_use_box(self):
        hi = HouseInfo(20, 'Road1', Oper_Pi, use_box=True)
        self.assertEqual(hi._use_box, DaySequence())

    def test_52_use_box(self):
        hi = HouseInfo(20, 'Road1', Oper_Pi, use_box=False)
コード例 #17
0
 def test_51_add_days_fail(self):
     pi = PaperInfo('Paper', '6')
     with self.assertRaises(ValueError) as e:
         pi.add_days('9')
     self.assertEqual(e.exception.args[0],
                      'Day sequence contains no valid days')
コード例 #18
0
 def test_01_init(self):
     with self.assertRaises(TypeError) as e:
         pi = PaperInfo()
     self.assertEqual(
         e.exception.args[0],
         "__init__() missing 1 required positional argument: 'name'")