Example #1
0
    def test_missing_ids_in_lookup(self):
        # Mapping for '1' is missing. Should get an error while remapping IDs
        # for the first distance matrix.
        lookup = {"0": "a", "2": "c"}

        with self.assertRaisesRegexp(KeyError, "first.*(x).*'1'\"$"):
            _order_dms(self.minx_dm, self.miny_dm, lookup=lookup)

        # Mapping for 'bar' is missing. Should get an error while remapping IDs
        # for the second distance matrix.
        lookup = {"0": "a", "1": "b", "2": "c", "foo": "a", "baz": "c"}
        self.miny_dm.ids = ("foo", "bar", "baz")

        with self.assertRaisesRegexp(KeyError, "second.*(y).*'bar'\"$"):
            _order_dms(self.minx_dm, self.miny_dm, lookup=lookup)
Example #2
0
    def test_missing_ids_in_lookup(self):
        # Mapping for '1' is missing. Should get an error while remapping IDs
        # for the first distance matrix.
        lookup = {'0': 'a', '2': 'c'}

        with self.assertRaisesRegexp(KeyError, "first.*(x).*'1'\"$"):
            _order_dms(self.minx_dm, self.miny_dm, lookup=lookup)

        # Mapping for 'bar' is missing. Should get an error while remapping IDs
        # for the second distance matrix.
        lookup = {'0': 'a', '1': 'b', '2': 'c', 'foo': 'a', 'baz': 'c'}
        self.miny_dm.ids = ('foo', 'bar', 'baz')

        with self.assertRaisesRegexp(KeyError, "second.*(y).*'bar'\"$"):
            _order_dms(self.minx_dm, self.miny_dm, lookup=lookup)
Example #3
0
    def test_missing_ids_in_lookup(self):
        # Mapping for '1' is missing. Should get an error while remapping IDs
        # for the first distance matrix.
        lookup = {'0': 'a', '2': 'c'}

        with self.assertRaisesRegex(KeyError, "first.*(x).*'1'\"$"):
            _order_dms(self.minx_dm, self.miny_dm, lookup=lookup)

        # Mapping for 'bar' is missing. Should get an error while remapping IDs
        # for the second distance matrix.
        lookup = {'0': 'a', '1': 'b', '2': 'c',
                  'foo': 'a', 'baz': 'c'}
        self.miny_dm.ids = ('foo', 'bar', 'baz')

        with self.assertRaisesRegex(KeyError, "second.*(y).*'bar'\"$"):
            _order_dms(self.minx_dm, self.miny_dm, lookup=lookup)
Example #4
0
    def test_id_lookup(self):
        # Matrices have mismatched IDs but a lookup is provided.
        self.minx_dm_extra.ids = ['a', 'b', 'c', 'foo']
        self.minz_dm_extra.ids = ['d', 'e', 'f', 'bar']
        lookup = {
            'a': '0',
            'b': '1',
            'c': '2',
            'foo': 'foo',
            'd': '0',
            'e': '1',
            'f': '2',
            'bar': 'bar'
        }

        x = self.minx_dm_extra.filter(['b', 'a', 'foo', 'c'])
        z = self.minz_dm_extra.filter(['bar', 'e', 'f', 'd'])

        x_copy = x.copy()
        z_copy = z.copy()

        exp = (self.minx_dm.filter(['1', '0',
                                    '2']), self.minz_dm.filter(['1', '0',
                                                                '2']))
        obs = _order_dms(x, z, strict=False, lookup=lookup)
        self.assertEqual(obs, exp)

        # Make sure the inputs aren't modified.
        self.assertEqual(x, x_copy)
        self.assertEqual(z, z_copy)
Example #5
0
    def test_reordered_and_nonmatching_distance_matrices(self):
        # Some matching and nonmatching IDs, with different ordering.
        x = self.minx_dm_extra.filter(['1', '0', 'foo', '2'])
        z = self.minz_dm_extra.filter(['bar', '0', '2', '1'])

        exp = (x.filter(['1', '0', '2']), z.filter(['1', '0', '2']))
        obs = _order_dms(x, z, strict=False)
        self.assertEqual(obs, exp)
Example #6
0
    def test_reordered_distance_matrices(self):
        # All matching IDs but with different orderings.
        x = self.minx_dm.filter(['1', '0', '2'])
        y = self.miny_dm.filter(['0', '2', '1'])

        exp = (x, y.filter(['1', '0', '2']))
        obs = _order_dms(x, y)
        self.assertEqual(obs, exp)
Example #7
0
    def test_reordered_distance_matrices(self):
        # All matching IDs but with different orderings.
        x = self.minx_dm.filter(['1', '0', '2'])
        y = self.miny_dm.filter(['0', '2', '1'])

        exp = (x, y.filter(['1', '0', '2']))
        obs = _order_dms(x, y)
        self.assertEqual(obs, exp)
Example #8
0
    def test_reordered_and_nonmatching_distance_matrices(self):
        # Some matching and nonmatching IDs, with different ordering.
        x = self.minx_dm_extra.filter(['1', '0', 'foo', '2'])
        z = self.minz_dm_extra.filter(['bar', '0', '2', '1'])

        exp = (x.filter(['1', '0', '2']), z.filter(['1', '0', '2']))
        obs = _order_dms(x, z, strict=False)
        self.assertEqual(obs, exp)
Example #9
0
    def test_reordered_and_nonmatching_distance_matrices(self):
        # Some matching and nonmatching IDs, with different ordering.
        x = self.minx_dm_extra.filter(["1", "0", "foo", "2"])
        z = self.minz_dm_extra.filter(["bar", "0", "2", "1"])

        exp = (x.filter(["1", "0", "2"]), z.filter(["1", "0", "2"]))
        obs = _order_dms(x, z, strict=False)
        self.assertEqual(obs, exp)
Example #10
0
    def test_id_lookup(self):
        # Matrices have mismatched IDs but a lookup is provided.
        self.minx_dm_extra.ids = ["a", "b", "c", "foo"]
        self.minz_dm_extra.ids = ["d", "e", "f", "bar"]
        lookup = {"a": "0", "b": "1", "c": "2", "foo": "foo", "d": "0", "e": "1", "f": "2", "bar": "bar"}

        x = self.minx_dm_extra.filter(["b", "a", "foo", "c"])
        z = self.minz_dm_extra.filter(["bar", "e", "f", "d"])

        x_copy = x.copy()
        z_copy = z.copy()

        exp = (self.minx_dm.filter(["1", "0", "2"]), self.minz_dm.filter(["1", "0", "2"]))
        obs = _order_dms(x, z, strict=False, lookup=lookup)
        self.assertEqual(obs, exp)

        # Make sure the inputs aren't modified.
        self.assertEqual(x, x_copy)
        self.assertEqual(z, z_copy)
Example #11
0
    def test_id_lookup(self):
        # Matrices have mismatched IDs but a lookup is provided.
        self.minx_dm_extra.ids = ['a', 'b', 'c', 'foo']
        self.minz_dm_extra.ids = ['d', 'e', 'f', 'bar']
        lookup = {'a': '0', 'b': '1', 'c': '2', 'foo': 'foo',
                  'd': '0', 'e': '1', 'f': '2', 'bar': 'bar'}

        x = self.minx_dm_extra.filter(['b', 'a', 'foo', 'c'])
        z = self.minz_dm_extra.filter(['bar', 'e', 'f', 'd'])

        x_copy = x.copy()
        z_copy = z.copy()

        exp = (self.minx_dm.filter(['1', '0', '2']),
               self.minz_dm.filter(['1', '0', '2']))
        obs = _order_dms(x, z, strict=False, lookup=lookup)
        self.assertEqual(obs, exp)

        # Make sure the inputs aren't modified.
        self.assertEqual(x, x_copy)
        self.assertEqual(z, z_copy)
Example #12
0
 def test_lookup_with_array_like(self):
     lookup = {'0': 'a', '1': 'b', '2': 'c'}
     with self.assertRaises(ValueError):
         _order_dms(self.minx, self.miny, lookup=lookup)
Example #13
0
    def test_no_matching_ids(self):
        self.minx_dm.ids = ["foo", "bar", "baz"]
        self.miny_dm.ids = ["a", "b", "c"]

        with self.assertRaises(ValueError):
            _order_dms(self.minx_dm, self.miny_dm, strict=False)
Example #14
0
 def test_lookup_with_array_like(self):
     lookup = {"0": "a", "1": "b", "2": "c"}
     with self.assertRaises(ValueError):
         _order_dms(self.minx, self.miny, lookup=lookup)
Example #15
0
    def test_mixed_input_types(self):
        with self.assertRaises(TypeError):
            _order_dms(self.minx, self.minz_dm)

        with self.assertRaises(TypeError):
            _order_dms(self.minz_dm, self.minx)
Example #16
0
 def test_array_like_input(self):
     obs = _order_dms(self.minx, self.miny)
     self.assertEqual(obs, (self.minx_dm, self.miny_dm))
Example #17
0
    def test_no_matching_ids(self):
        self.minx_dm.ids = ['foo', 'bar', 'baz']
        self.miny_dm.ids = ['a', 'b', 'c']

        with self.assertRaises(ValueError):
            _order_dms(self.minx_dm, self.miny_dm, strict=False)
Example #18
0
 def test_nonmatching_ids_strict_true(self):
     with self.assertRaises(ValueError):
         _order_dms(self.minx_dm, self.minz_dm_extra, strict=True)
Example #19
0
 def test_array_like_input(self):
     obs = _order_dms(self.minx, self.miny)
     self.assertEqual(obs, (self.minx_dm, self.miny_dm))
Example #20
0
 def test_shape_mismatch(self):
     with self.assertRaises(ValueError):
         _order_dms(self.minx, [[0, 2], [2, 0]])
Example #21
0
    def test_no_matching_ids(self):
        self.minx_dm.ids = ['foo', 'bar', 'baz']
        self.miny_dm.ids = ['a', 'b', 'c']

        with self.assertRaises(ValueError):
            _order_dms(self.minx_dm, self.miny_dm, strict=False)
Example #22
0
 def test_nonmatching_ids_strict_true(self):
     with self.assertRaises(ValueError):
         _order_dms(self.minx_dm, self.minz_dm_extra, strict=True)
Example #23
0
 def test_lookup_with_array_like(self):
     lookup = {'0': 'a', '1': 'b', '2': 'c'}
     with self.assertRaises(ValueError):
         _order_dms(self.minx, self.miny, lookup=lookup)
Example #24
0
    def test_mixed_input_types(self):
        with self.assertRaises(TypeError):
            _order_dms(self.minx, self.minz_dm)

        with self.assertRaises(TypeError):
            _order_dms(self.minz_dm, self.minx)
Example #25
0
 def test_shape_mismatch(self):
     with self.assertRaises(ValueError):
         _order_dms(self.minx, [[0, 2], [2, 0]])