Exemple #1
0
 def test_can_save_as_xyz(self, mock_open, mock_string):
     open_return = MagicMock()
     mock_file = Mock()
     mock_write = MagicMock()
     mock_file.write = mock_write
     open_return.__enter__.return_value = mock_file
     mock_open.return_value = open_return
     f = File()
     f.save("/path/file.xyz")
     mock_string.assert_called_with(f)
     mock_open.assert_called_once_with("/path/file.xyz", "w")
     mock_write.assert_called_with(mock_string.return_value)
Exemple #2
0
 def test_unknown_file_extension(self):
     f = File()
     with self.assertRaises(ValueError):
         f.save("/path/file.abc")