import unittest
import distarray as da
from distarray.mpi.mpibase import create_comm_of_size, InvalidCommSizeError


class TestDistributedArrayProtocol(unittest.TestCase):

    def setUp(self):
        try:
            comm = create_comm_of_size(4)
        except InvalidCommSizeError:
            raise unittest.SkipTest('Must run with comm size > 4.')
        else:
            self.larr = da.LocalArray((16,16),
                                     grid_shape=(4,),
                                     comm=comm, buf=None, offset=0)

    def test_has_export(self):
        self.assertTrue(hasattr(self.larr, '__distarray__'))

    def test_export_keys(self):
        required_keys = set(("buffer", "dimdata"))
        export_data = self.larr.__distarray__()
        exported_keys = set(export_data.keys())
        self.assertEqual(required_keys, exported_keys)

    def test_export_buffer(self):
        """See if we actually export a buffer."""
        export_data = self.larr.__distarray__()
        memoryview(export_data['buffer'])

    def test_round_trip(self):
        new_larr = da.localarray(self.larr)
        self.assertEqual(new_larr.local_array, self.larr.local_array)


if __name__ == '__main__':
    try:
        unittest.main()
    except SystemExit:
        pass

import unittest
import distarray as da
from distarray.mpi.mpibase import create_comm_of_size, InvalidCommSizeError


class TestDistributedArrayProtocol(unittest.TestCase):

    def setUp(self):
        try:
            comm = create_comm_of_size(4)
        except InvalidCommSizeError:
            raise unittest.SkipTest('Must run with comm size > 4.')
        else:
            self.larr = da.LocalArray((16,16),
                                     grid_shape=(4,),
                                     comm=comm, buf=None, offset=0)

    def test_has_export(self):
        self.assertTrue(hasattr(self.larr, '__distarray__'))

    def test_export_keys(self):
        required_keys = set(("buffer", "dimdata"))
        export_data = self.larr.__distarray__()
        exported_keys = set(export_data.keys())
        self.assertEqual(required_keys, exported_keys)

    def test_export_buffer(self):
        """See if we actually export a buffer."""
        export_data = self.larr.__distarray__()
        memoryview(export_data['buffer'])

    @unittest.skip("Import not yet implemented.")
    def test_round_trip(self):
        new_larr = da.fromdap(self.larr)
        self.assertIs(new_larr.local_array, self.larr.local_array)


if __name__ == '__main__':
    try:
        unittest.main()
    except SystemExit:
        pass

Modify round-trip test to use new function name.
Modify round-trip test to use new function name.

We've temporarily settled on `fromdap()` for importing from `__distarray__` interfaces.
  import unittest
  import distarray as da
  from distarray.mpi.mpibase import create_comm_of_size, InvalidCommSizeError
  
  
  class TestDistributedArrayProtocol(unittest.TestCase):
  
      def setUp(self):
          try:
              comm = create_comm_of_size(4)
          except InvalidCommSizeError:
              raise unittest.SkipTest('Must run with comm size > 4.')
          else:
              self.larr = da.LocalArray((16,16),
                                       grid_shape=(4,),
                                       comm=comm, buf=None, offset=0)
  
      def test_has_export(self):
          self.assertTrue(hasattr(self.larr, '__distarray__'))
  
      def test_export_keys(self):
          required_keys = set(("buffer", "dimdata"))
          export_data = self.larr.__distarray__()
          exported_keys = set(export_data.keys())
          self.assertEqual(required_keys, exported_keys)
  
      def test_export_buffer(self):
          """See if we actually export a buffer."""
          export_data = self.larr.__distarray__()
          memoryview(export_data['buffer'])
  
+     @unittest.skip("Import not yet implemented.")
      def test_round_trip(self):
-         new_larr = da.localarray(self.larr)
+         new_larr = da.fromdap(self.larr)
-         self.assertEqual(new_larr.local_array, self.larr.local_array)
+         self.assertIs(new_larr.local_array, self.larr.local_array)
  
  
  if __name__ == '__main__':
      try:
          unittest.main()
      except SystemExit:
          pass
  
Modify round-trip test to use new function name.
## Code Before:
import unittest
import distarray as da
from distarray.mpi.mpibase import create_comm_of_size, InvalidCommSizeError


class TestDistributedArrayProtocol(unittest.TestCase):

    def setUp(self):
        try:
            comm = create_comm_of_size(4)
        except InvalidCommSizeError:
            raise unittest.SkipTest('Must run with comm size > 4.')
        else:
            self.larr = da.LocalArray((16,16),
                                     grid_shape=(4,),
                                     comm=comm, buf=None, offset=0)

    def test_has_export(self):
        self.assertTrue(hasattr(self.larr, '__distarray__'))

    def test_export_keys(self):
        required_keys = set(("buffer", "dimdata"))
        export_data = self.larr.__distarray__()
        exported_keys = set(export_data.keys())
        self.assertEqual(required_keys, exported_keys)

    def test_export_buffer(self):
        """See if we actually export a buffer."""
        export_data = self.larr.__distarray__()
        memoryview(export_data['buffer'])

    def test_round_trip(self):
        new_larr = da.localarray(self.larr)
        self.assertEqual(new_larr.local_array, self.larr.local_array)


if __name__ == '__main__':
    try:
        unittest.main()
    except SystemExit:
        pass

## Instruction:
Modify round-trip test to use new function name.
## Code After:
import unittest
import distarray as da
from distarray.mpi.mpibase import create_comm_of_size, InvalidCommSizeError


class TestDistributedArrayProtocol(unittest.TestCase):

    def setUp(self):
        try:
            comm = create_comm_of_size(4)
        except InvalidCommSizeError:
            raise unittest.SkipTest('Must run with comm size > 4.')
        else:
            self.larr = da.LocalArray((16,16),
                                     grid_shape=(4,),
                                     comm=comm, buf=None, offset=0)

    def test_has_export(self):
        self.assertTrue(hasattr(self.larr, '__distarray__'))

    def test_export_keys(self):
        required_keys = set(("buffer", "dimdata"))
        export_data = self.larr.__distarray__()
        exported_keys = set(export_data.keys())
        self.assertEqual(required_keys, exported_keys)

    def test_export_buffer(self):
        """See if we actually export a buffer."""
        export_data = self.larr.__distarray__()
        memoryview(export_data['buffer'])

    @unittest.skip("Import not yet implemented.")
    def test_round_trip(self):
        new_larr = da.fromdap(self.larr)
        self.assertIs(new_larr.local_array, self.larr.local_array)


if __name__ == '__main__':
    try:
        unittest.main()
    except SystemExit:
        pass
