Пример #1
0
 def test_read_in_data(self, mock_latin):
     mock_latin.return_value = [{'a': 'd', 'b': 'e', 'c': 'f'}]
     m = mock_open(read_data='a,b,c\nd,e,f')
     with patch("__builtin__.open", m, create=True):
         data = read_in_data('mockfile.csv')
     self.assertTrue(m.call_count == 1)
     self.assertTrue(data == [{'a': 'd', 'b': 'e', 'c': 'f'}])
     # m.side_effect = Exception("OPEN ERROR")
     m2 = mock_open(read_data='a,b,c\nd,e,f')
     m2.side_effect = UnicodeDecodeError('bad character', '2', 3, 4, '5')
     with patch("__builtin__.open", m, create=True):
         data = read_in_data('mockfile.csv')
     self.assertTrue(m.call_count == 2)
     self.assertTrue(data == [{'a': 'd', 'b': 'e', 'c': 'f'}])
Пример #2
0
 def test_read_in_data(self, mock_latin):
     mock_latin.return_value = [{'a': 'd', 'b': 'e', 'c': 'f'}]
     m = mock_open(read_data='a,b,c\nd,e,f')
     with patch("__builtin__.open", m, create=True):
         data = read_in_data('mockfile.csv')
     self.assertTrue(m.call_count == 1)
     self.assertTrue(data == [{'a': 'd', 'b': 'e', 'c': 'f'}])
     # m.side_effect = Exception("OPEN ERROR")
     m2 = mock_open(read_data='a,b,c\nd,e,f')
     m2.side_effect = UnicodeDecodeError('bad character', '2', 3, 4, '5')
     with patch("__builtin__.open", m, create=True):
         data = read_in_data('mockfile.csv')
     self.assertTrue(m.call_count == 2)
     self.assertTrue(data == [{'a': 'd', 'b': 'e', 'c': 'f'}])
Пример #3
0
 def test_try_latin(self, mock_cdr, mock_latin):
     mock_cdr.side_effect = UnicodeDecodeError('bad character',
                                               '2', 3, 4, '5')
     mock_latin.return_value = [{'a': 'd', 'b': 'e', 'c': 'f'}]
     m = mock_open(read_data='a,b,c\nd,e,f')
     with patch("__builtin__.open", m, create=True):
         data = read_in_data('mockfile.csv')
     self.assertTrue(m.call_count == 1)
     self.assertTrue(mock_cdr.call_count == 1)
     self.assertTrue(mock_latin.call_count == 1)
     mock_cdr.side_effect = TypeError
     with patch("__builtin__.open", m, create=True):
         data = read_in_data('mockfile.csv')
     self.assertTrue(m.call_count == 2)
     self.assertTrue(data == [{}])
Пример #4
0
 def test_try_latin(self, mock_cdr, mock_latin):
     mock_cdr.side_effect = UnicodeDecodeError('bad character', '2', 3, 4,
                                               '5')
     mock_latin.return_value = [{'a': 'd', 'b': 'e', 'c': 'f'}]
     m = mock_open(read_data='a,b,c\nd,e,f')
     with patch("__builtin__.open", m, create=True):
         data = read_in_data('mockfile.csv')
     self.assertTrue(m.call_count == 1)
     self.assertTrue(mock_cdr.call_count == 1)
     self.assertTrue(mock_latin.call_count == 1)
     mock_cdr.side_effect = TypeError
     with patch("__builtin__.open", m, create=True):
         data = read_in_data('mockfile.csv')
     self.assertTrue(m.call_count == 2)
     self.assertTrue(data == [{}])
 def test_read_in_data(self):
     # mock_return = [{'a': 'd', 'b': 'e', 'c': 'f'}]
     m = mock_open(read_data='a,b,c\nd,e,f')
     with patch("builtins.open", m):
         read_in_data('mockfile.csv')
     self.assertEqual(m.call_count, 1)