Exemplo n.º 1
0
 def test_unpacks_three_tracers_in_order_registered(self):
     np.random.seed(0)
     dims = ['tracer', '*']
     register_tracer('tracer1', 'g/m^3')
     register_tracer('tracer2', 'kg'),
     register_tracer('tracer3', 'kg/m^3')
     state = {
         'tracer1': DataArray(np.random.randn(5), dims=['dim1'], attrs={'units': 'g/m^3'}),
         'tracer2': DataArray(np.random.randn(5), dims=['dim1'], attrs={'units': 'kg'}),
         'tracer3': DataArray(np.random.randn(5), dims=['dim1'], attrs={'units': 'kg/m^3'}),
     }
     packer = TracerPacker(self.component, dims)
     packed = packer.pack(state)
     unpacked = packer.unpack(packed, state)
     assert isinstance(unpacked, dict)
     assert len(unpacked) == 3
     assert np.all(unpacked['tracer1'] == state['tracer1'])
     assert np.all(unpacked['tracer2'] == state['tracer2'])
     assert np.all(unpacked['tracer3'] == state['tracer3'])
Exemplo n.º 2
0
 def test_unpacks_no_tracers(self):
     dims = ['tracer', '*']
     packer = TracerPacker(self.component, dims)
     unpacked = packer.unpack({}, {})
     assert isinstance(unpacked, dict)
     assert len(unpacked) == 0