Esempio n. 1
0
    def test_attributes(self):
        """Testing the attribute setting after initialization.

        * Case 1: Default attributes.
        * Case 2: Initializing with a list.
        * Case 3: Initializing with a deque.
        * Case 4: Raising a TypeError if not initializing with a list or a deque.
        """
        # Test default attributes
        WLM = WorkingListManager()
        self.assertEqual(WLM.name, 'workingList')
        self.assertEqual(WLM.path, 'tmp/workingList.txt')
        self.assertEqual(WLM.donePath, 'tmp/done.txt')
        self.assertTrue(isinstance(WLM.records, deque))
        self.assertFalse(WLM.records) # Records deque is empty
        self.assertTrue(isinstance(WLM.done, list))

        # Test attributes of initializing with a list
        WLM = WorkingListManager(['aaa'])
        self.assertTrue(isinstance(WLM.records, deque) and WLM.records)
        self.assertEqual(WLM.records.pop(), 'aaa')

        # Test attributes of initializing with a deque
        WLM = WorkingListManager(deque(['bbb']))
        self.assertTrue(isinstance(WLM.records, deque) and WLM.records)
        self.assertEqual(WLM.records, deque(['bbb']))

        # Test raising a TypeError if not initializing with a list or a deque
        with self.assertRaises(TypeError):
            WorkingListManager('')
Esempio n. 2
0
 def test_addWork(self):
     """Testing method of adding a work.
     """
     newWork = 'abc'
     WLM = WorkingListManager()
     WLM.addWork(newWork)
     self.assertEqual(WLM.records, deque([newWork])) # Record list correctness 
     with open(WLM.path, 'r') as fin:
         self.assertEqual(fin.read(), 'abc') # File correctness of auto saving after adding a work
Esempio n. 3
0
    def test_addWorks(self):
        """Testing method of adding multiple works.
        """
        newWorks = ['abc', 'klm']
        expectedRecords = deque(newWorks)
        expectedData = 'abc\nklm'

        WLM = WorkingListManager()
        WLM.addWorks(newWorks)

        self.assertEqual(WLM.records, expectedRecords) # Record list correctness 
        with open(WLM.path, 'r') as fin:
            self.assertEqual(fin.read(), expectedData) # File correctness of auto saving after adding a work
Esempio n. 4
0
    def test_getWork(self):
        """Testing method of getting a work.
        """
        newWorks = ['abc', 'klm', 'rts']
        expectedWork = 'abc'
        expectedRecords = deque(['klm', 'rts'])
        expectedData = 'klm\nrts'

        WLM = WorkingListManager()
        WLM.addWorks(newWorks)
        work = WLM.getWork()

        self.assertEqual(work, expectedWork) # Returning data correctness
        self.assertEqual(WLM.records, expectedRecords) # Record list correctness
        with open(WLM.path, 'r') as fin:
            self.assertEqual(fin.read(), expectedData) # File correctness of auto saving after getting a work
Esempio n. 5
0
    def test_save(self):
        """Testing saving method.
        """
        # Testing auto saving after initialization
        WLM = WorkingListManager(['first work', 'second work'])
        self.assertTrue(os.path.exists(WLM.path) and os.path.isfile(WLM.path)) # Working list records exists
        with open(WLM.path) as fin:
            self.assertEqual(fin.read(), 'first work\nsecond work') # File correctness
        self.assertTrue(os.path.exists(WLM.donePath) and os.path.isfile(WLM.donePath)) # Done list exists
        with open(WLM.donePath) as fin:
            self.assertEqual(fin.read(), '') # File correctness

        # Testing auto saving after getting a work
        WLM.getWork()
        with open(WLM.path) as fin:
            self.assertEqual(fin.read(), 'second work')
        with open(WLM.donePath) as fin:
            self.assertEqual(fin.read(), 'first work')

        # Testing auto saving after getting a work
        WLM.getWork()
        with open(WLM.path) as fin:
            self.assertEqual(fin.read(), '')
        with open(WLM.donePath) as fin:
            self.assertEqual(fin.read(), 'first work\nsecond work')
Esempio n. 6
0
 def test_workExists(self):
     """Testing method of checking the existence of work.
     """
     WLM = WorkingListManager()
     self.assertFalse(WLM.workExists()) # No record exists if initialize without working list
     newWork = 'abc'
     WLM.addWork(newWork)
     self.assertTrue(WLM.workExists()) # Record exists after append a recorder to the record list
Esempio n. 7
0
    def test_remainedAmount(self):
        """Testing method of checking the amount of works.
        """
        WLM = WorkingListManager()
        self.assertEqual(WLM.remainedAmount(), 0) # Work amount correctness of initial state
        
        newWork = 'abc'        
        WLM.addWork(newWork)
        self.assertEqual(WLM.remainedAmount(), 1) # Work amount correctness after adding a work
        
        for i in range(10):
            WLM.addWork(str(i))
        self.assertEqual(WLM.remainedAmount(), 11) # Work amount correctness after adding a work for serveral times

        newRecords = ['aaa', 'bbb', 'ccc']
        WLM.addWorks(newRecords)
        self.assertEqual(WLM.remainedAmount(), 14) # Work amount correctness after adding works