Repository: Qiskit/qiskit

Issue:
String formating bug in Coupling
The descriptions of qubits are tuple (e.g. `('q',0)`) that are not automatically converted to strings when `"%s not in coupling graph" % q1`, a `TypeError: not all arguments converted during string formatting` raises.

### Informations

- **Qiskit Terra version**: 0.6.0
- **Python version**: 3.6.1
- **Operating system**: MacOS

### What is the current behavior?
```
In [1]: from qiskit.mapper._coupling import Coupling
In [2]: graph = Coupling({0: [1, 2], 1: [2]})
In [3]: graph.distance(('q0',0),('q1',1))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-88a8c8c0c516> in <module>()
----> 1 graph.distance(('q0',0),('q1',1))

/Users/luciano.bello/repos/qiskit-terra/qiskit/mapper/_coupling.py in distance(self, q1, q2)
    168             raise CouplingError("distance has not been computed")
    169         if q1 not in self.qubits:
--> 170             raise CouplingError("%s not in coupling graph" % q1)
    171         if q2 not in self.qubits:
    172             raise CouplingError("%s not in coupling graph" % q2)

TypeError: not all arguments converted during string formatting
```

### What is the expected behavior?
```
In [1]: from qiskit.mapper._coupling import Coupling
In [2]: graph = Coupling({0: [1, 2], 1: [2]})
In [3]: graph.distance(('q0',0),('q1',1))
---------------------------------------------------------------------------
CouplingError                             Traceback (most recent call last)
<ipython-input-3-88a8c8c0c516> in <module>()
----> 1 graph.distance(('q0',0),('q1',1))

/Users/luciano.bello/repos/qiskit-terra/qiskit/mapper/_coupling.py in distance(self, q1, q2)
    169             raise CouplingError("distance has not been computed")
    170         if q1 not in self.qubits:
--> 171             raise CouplingError("%s not in coupling graph" % (q1,))
    172         if q2 not in self.qubits:
    173             raise CouplingError("%s not in coupling graph" % (q2,))

CouplingError: "('q0', 0) not in coupling graph"
```

### Suggested solutions

#738 




Discussion:

Resolving patch:
diff --git a/qiskit/mapper/_coupling.py b/qiskit/mapper/_coupling.py
--- a/qiskit/mapper/_coupling.py
+++ b/qiskit/mapper/_coupling.py
@@ -65,6 +65,7 @@ class Coupling:
     Nodes correspond to qubits and directed edges correspond to permitted
     CNOT gates
     """
+
     # pylint: disable=invalid-name
 
     def __init__(self, couplingdict=None):
@@ -175,9 +176,9 @@ def distance(self, q1, q2):
         if self.dist is None:
             raise CouplingError("distance has not been computed")
         if q1 not in self.qubits:
-            raise CouplingError("%s not in coupling graph" % q1)
+            raise CouplingError("%s not in coupling graph" % (q1,))
         if q2 not in self.qubits:
-            raise CouplingError("%s not in coupling graph" % q2)
+            raise CouplingError("%s not in coupling graph" % (q2,))
         return self.dist[q1][q2]
 
     def __str__(self):


Test patch:
diff --git a/test/python/test_coupling.py b/test/python/test_coupling.py
new file mode 100644
--- /dev/null
+++ b/test/python/test_coupling.py
@@ -0,0 +1,29 @@
+# -*- coding: utf-8 -*-
+
+# Copyright 2018, IBM.
+#
+# This source code is licensed under the Apache License, Version 2.0 found in
+# the LICENSE.txt file in the root directory of this source tree.
+
+# pylint: disable=invalid-name
+
+"""Coupling Graph Test: Directed graph object for representing coupling between qubits."""
+
+import unittest
+from qiskit.mapper._coupling import Coupling
+from qiskit.mapper._couplingerror import CouplingError
+from .common import QiskitTestCase
+
+
+class TestCoupling(QiskitTestCase):
+    """Qiskit Coupling Graph Tests."""
+
+    def test_distance_error(self):
+        """Test distance method validation.
+        """
+        graph = Coupling({0: [1, 2], 1: [2]})
+        self.assertRaises(CouplingError, graph.distance, ('q0', 0), ('q1', 1))
+
+
+if __name__ == '__main__':
+    unittest.main(verbosity=2)