Version 1.0.3
[linpy.git] / linpy / tests / test_linexprs.py
index 9599d06..0c50e6c 100644 (file)
 # You should have received a copy of the GNU General Public License
 # along with LinPy.  If not, see <http://www.gnu.org/licenses/>.
 
 # You should have received a copy of the GNU General Public License
 # along with LinPy.  If not, see <http://www.gnu.org/licenses/>.
 
-import functools
 import unittest
 
 from fractions import Fraction
 
 import unittest
 
 from fractions import Fraction
 
-from ..linexprs import *
+from ..linexprs import Dummy, LinExpr, Rational, Symbol, symbols
 from .libhelper import requires_sympy
 
 
 from .libhelper import requires_sympy
 
 
@@ -76,7 +75,8 @@ class TestLinExpr(unittest.TestCase):
             self.expr[self.expr]
 
     def test_coefficients(self):
             self.expr[self.expr]
 
     def test_coefficients(self):
-        self.assertListEqual(list(self.expr.coefficients()), [(self.x, 1), (self.y, -2)])
+        self.assertListEqual(list(self.expr.coefficients()),
+                             [(self.x, 1), (self.y, -2)])
 
     def test_constant(self):
         self.assertEqual(self.x.constant, 0)
 
     def test_constant(self):
         self.assertEqual(self.x.constant, 0)
@@ -151,7 +151,7 @@ class TestLinExpr(unittest.TestCase):
 
     def test_scaleint(self):
         self.assertEqual((self.x + self.y/2 + self.z/3).scaleint(),
 
     def test_scaleint(self):
         self.assertEqual((self.x + self.y/2 + self.z/3).scaleint(),
-                6*self.x + 3*self.y + 2*self.z)
+                         6*self.x + 3*self.y + 2*self.z)
 
     def test_subs(self):
         self.assertEqual(self.x.subs(self.x, 3), 3)
 
     def test_subs(self):
         self.assertEqual(self.x.subs(self.x, 3), 3)
@@ -161,9 +161,12 @@ class TestLinExpr(unittest.TestCase):
         self.assertEqual(self.x.subs(self.y, 3), self.x)
         self.assertEqual(self.pi.subs(self.x, 3), self.pi)
         self.assertEqual(self.expr.subs(self.x, -3), -2 * self.y)
         self.assertEqual(self.x.subs(self.y, 3), self.x)
         self.assertEqual(self.pi.subs(self.x, 3), self.pi)
         self.assertEqual(self.expr.subs(self.x, -3), -2 * self.y)
-        self.assertEqual(self.expr.subs([(self.x, self.y), (self.y, self.x)]), 3 - self.x)
-        self.assertEqual(self.expr.subs({self.x: self.z, self.y: self.z}), 3 - self.z)
-        self.assertEqual(self.expr.subs({self.x: self.z, self.y: self.z}), 3 - self.z)
+        self.assertEqual(self.expr.subs([(self.x, self.y), (self.y, self.x)]),
+                         -2*self.x + self.y + 3)
+        self.assertEqual(self.expr.subs({self.x: self.z, self.y: self.z}),
+                         3 - self.z)
+        self.assertEqual(self.expr.subs({self.x: self.z, self.y: self.z}),
+                         3 - self.z)
         with self.assertRaises(TypeError):
             self.x.subs('x', 3)
         with self.assertRaises(TypeError):
         with self.assertRaises(TypeError):
             self.x.subs('x', 3)
         with self.assertRaises(TypeError):
@@ -195,7 +198,7 @@ class TestLinExpr(unittest.TestCase):
         self.assertEqual(LinExpr.fromsympy(sp_x), self.x)
         self.assertEqual(LinExpr.fromsympy(sympy.Rational(22, 7)), self.pi)
         self.assertEqual(LinExpr.fromsympy(sp_x - 2*sp_y + 3), self.expr)
         self.assertEqual(LinExpr.fromsympy(sp_x), self.x)
         self.assertEqual(LinExpr.fromsympy(sympy.Rational(22, 7)), self.pi)
         self.assertEqual(LinExpr.fromsympy(sp_x - 2*sp_y + 3), self.expr)
-        with self.assertRaises(ValueError):
+        with self.assertRaises(TypeError):
             LinExpr.fromsympy(sp_x*sp_y)
 
     @requires_sympy
             LinExpr.fromsympy(sp_x*sp_y)
 
     @requires_sympy