Example #1
0
 def test_save(self):
     m = mock.mock_open()
     with mock.patch('__builtin__.open', m, create=True):
         # sending a MagicMock object to gribapi raises an AssertionError
         # as the gribapi code does a type check
         # this is deemed acceptable within the scope of this unit test
         with self.assertRaises(AssertionError):
             grib.save_messages([self.grib_message], 'foo.grib2')
     self.assertTrue(call('foo.grib2', 'wb') in m.mock_calls)
Example #2
0
 def test_save(self):
     m = mock.mock_open()
     with mock.patch('__builtin__.open', m, create=True):
         # sending a MagicMock object to gribapi raises an AssertionError
         # as the gribapi code does a type check
         # this is deemed acceptable within the scope of this unit test
         with self.assertRaises(AssertionError):
             grib.save_messages([self.grib_message], 'foo.grib2')
     self.assertTrue(call('foo.grib2', 'wb') in m.mock_calls)
Example #3
0
 def test_save_append(self):
     if six.PY3:
         open_func = "builtins.open"
     else:
         open_func = "__builtin__.open"
     m = mock.mock_open()
     with mock.patch(open_func, m, create=True):
         # sending a MagicMock object to gribapi raises an AssertionError
         # as the gribapi code does a type check
         # this is deemed acceptable within the scope of this unit test
         with self.assertRaises((AssertionError, TypeError)):
             grib.save_messages([self.grib_message], "foo.grib2", append=True)
     self.assertTrue(mock.call("foo.grib2", "ab") in m.mock_calls)
Example #4
0
 def test_save_append(self):
     if six.PY3:
         open_func = 'builtins.open'
     else:
         open_func = '__builtin__.open'
     m = mock.mock_open()
     with mock.patch(open_func, m, create=True):
         # sending a MagicMock object to gribapi raises an AssertionError
         # as the gribapi code does a type check
         # this is deemed acceptable within the scope of this unit test
         with self.assertRaises(AssertionError):
             grib.save_messages([self.grib_message],
                                'foo.grib2',
                                append=True)
     self.assertTrue(mock.call('foo.grib2', 'ab') in m.mock_calls)