コード例 #1
0
    def test_should_handle_invalid_file(self):
        param = '-f'
        file = 'test_files/NotAnXML.xml'
        testargs = ['test_PyBooksParser', param, file]
        with patch.object(sys, 'argv', testargs):
            ret = PyBooksParser.py_book_parser()
            self.assertEqual(ret, ['Provided file is not and XML file, please select XML file'])

        file = 'test_files'
        testargs = ['test_PyBooksParser', param, file]
        with patch.object(sys, 'argv', testargs):
            ret = PyBooksParser.py_book_parser()
            self.assertEqual(ret, ['Provided file is a directory, please select an XML file'])
コード例 #2
0
 def test_should_handle_non_existing_file(self):
     param = '-f'
     file = 'test_files/NotExistingFile.xml'
     testargs = ['test_PyBooksParser', param, file]
     with patch.object(sys, 'argv', testargs):
         ret = PyBooksParser.py_book_parser()
         self.assertEqual(ret, ["Provided file doesn't exist"])
コード例 #3
0
 def test_should_return_list_of_tuples(self):
     param = '-f'
     file = 'test_files/Books.xml'
     testargs = ['test_PyBooksParser', param, file]
     with patch.object(sys, 'argv', testargs):
         ret = PyBooksParser.py_book_parser()
         self.assertIs(type(ret), list)
         self.assertTrue(all([isinstance(x, tuple) for x in ret]))
コード例 #4
0
 def test_should_return_correct_data(self):
     param = '-f'
     file = 'test_files/Books.xml'
     testargs = ['test_PyBooksParser', param, file]
     with patch.object(sys, 'argv', testargs):
         ret = PyBooksParser.py_book_parser()
         some_book = (
             'bk112', 'Galos, Mike', 'Visual Studio 7: A Comprehensive Guide', 'Computer', '49.95', '2001-04-16',
             'Microsoft Visual Studio 7 is explored in depth,'
             '\n      looking at how Visual Basic, Visual C++, C#, and ASP+ are '
             '\n      integrated into a comprehensive development '
             '\n      environment.')
         self.assertIn((some_book), ret)