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):
         pp.save_fields([self.pp_field], 'foo.pp', append=True)
     self.assertTrue(mock.call('foo.pp', 'ab') in m.mock_calls)
     self.assertTrue(mock.call().write('saved') in m.mock_calls)
示例#2
0
 def test_save(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')
     self.assertTrue(mock.call('foo.grib2', 'wb') in m.mock_calls)
示例#3
0
 def test_save(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')
     self.assertTrue(mock.call('foo.grib2', 'wb') in m.mock_calls)
示例#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, TypeError)):
             grib.save_messages([self.grib_message], "foo.grib2", append=True)
     self.assertTrue(mock.call("foo.grib2", "ab") in m.mock_calls)