Пример #1
0
    def setUp(self):

        self.new_key = (5, 6)
        self.mapping = {
            (1, 2): {
                'key': 1
            },
            (2, 1): {
                'key': 2,
                'extra': True
            },
            (3, 2): {
                'key': 3,
                'type': 'node'
            },
            (4, 5): {
                'key': 4,
                'weight': 1.33
            },
            (2, 5): {
                'key': 5,
                'weight': 3.11
            }
        }

        self.storage_instance = ArrayStorage
        self.storage = ArrayStorage(self.mapping)
Пример #2
0
    def setUp(self):

        self.new_key = 'six'
        self.mapping = {
            'one': {
                'key': 1
            },
            'two': {
                'key': 2,
                'extra': True
            },
            'three': {
                'key': 3,
                'type': 'node'
            },
            'four': {
                'key': 4,
                'weight': 1.33
            },
            'five': {
                'key': 5,
                'weight': 3.11
            }
        }

        self.storage_instance = ArrayStorage
        self.storage = ArrayStorage(self.mapping)
class TestArrayStorageEdges(_BaseStorageDriverTests, UnittestPythonCompatibility):
    """
    Unit tests for ArrayStorage class storing nodes
    """

    def setUp(self):

        self.new_key = (5, 6)
        self.mapping = {(1, 2): {'key': 1},
                        (2, 1): {'key': 2, 'extra': True},
                        (3, 2): {'key': 3, 'type': 'node'},
                        (4, 5): {'key': 4, 'weight': 1.33},
                        (2, 5): {'key': 5, 'weight': 3.11}}

        self.storage_instance = ArrayStorage
        self.storage = ArrayStorage(self.mapping)

    def assertDictEqual(self, expected_seq, actual_seq, msg=None):
        """
        Convert actual_seq to dictionary

        The actual_seq is a DataFrame or Series in a ArrayStore. Although they
        behave as dictionaries they will not pass the isinstance == dict test
        of the default assertDictEqual.

        Convert actual_seq to dictionary explicitly by calling its 'to_dict'
        method then passing it to assertDictEqual.
        """

        if not isinstance(actual_seq, dict):
            actual_seq = actual_seq.to_dict()

        return super(TestArrayStorageEdges, self).assertDictEqual(expected_seq, actual_seq)

    def assertViewEqual(self, expected_seq, actual_seq, msg=None):
        """
        Test equality in items even if they are 'view' based
        """

        new = []
        for item in actual_seq:
            if isinstance(item, tuple):
                if hasattr(item[1], 'to_dict'):
                    new.append((item[0], item[1].to_dict()))
                else:
                    new.append(item)
            else:
                if hasattr(item, 'to_dict'):
                    new.append(item.to_dict())
                else:
                    new.append(item)

        return all([t in new for t in expected_seq]) and all([t in expected_seq for t in new])

    def test_arraystorage_dataframe_methods(self):
        """
        Test access to DataFrame methods from the ArrayStorage instance
        """

        self.assertIsNotNone(self.storage.describe())
        self.assertIsNotNone(self.storage.index)