m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

714 lines
23 KiB

6 months ago
  1. import inspect
  2. import copy
  3. import pickle
  4. from sympy.physics.units import meter
  5. from sympy.testing.pytest import XFAIL, raises
  6. from sympy.core.basic import Atom, Basic
  7. from sympy.core.core import BasicMeta
  8. from sympy.core.singleton import SingletonRegistry
  9. from sympy.core.symbol import Str, Dummy, Symbol, Wild
  10. from sympy.core.numbers import (E, I, pi, oo, zoo, nan, Integer,
  11. Rational, Float, AlgebraicNumber)
  12. from sympy.core.relational import (Equality, GreaterThan, LessThan, Relational,
  13. StrictGreaterThan, StrictLessThan, Unequality)
  14. from sympy.core.add import Add
  15. from sympy.core.mul import Mul
  16. from sympy.core.power import Pow
  17. from sympy.core.function import Derivative, Function, FunctionClass, Lambda, \
  18. WildFunction
  19. from sympy.sets.sets import Interval
  20. from sympy.core.multidimensional import vectorize
  21. from sympy.external.gmpy import HAS_GMPY
  22. from sympy.utilities.exceptions import SymPyDeprecationWarning
  23. from sympy.core.singleton import S
  24. from sympy.core.symbol import symbols
  25. from sympy.external import import_module
  26. cloudpickle = import_module('cloudpickle')
  27. excluded_attrs = {
  28. '_assumptions', # This is a local cache that isn't automatically filled on creation
  29. '_mhash', # Cached after __hash__ is called but set to None after creation
  30. 'is_EmptySet', # Deprecated from SymPy 1.5. This can be removed when is_EmptySet is removed.
  31. 'expr_free_symbols', # Deprecated from SymPy 1.9. This can be removed when exr_free_symbols is removed.
  32. '_mat', # Deprecated from SymPy 1.9. This can be removed when Matrix._mat is removed
  33. '_smat', # Deprecated from SymPy 1.9. This can be removed when SparseMatrix._smat is removed
  34. }
  35. def check(a, exclude=[], check_attr=True):
  36. """ Check that pickling and copying round-trips.
  37. """
  38. # Pickling with protocols 0 and 1 is disabled for Basic instances:
  39. if isinstance(a, Basic):
  40. for protocol in [0, 1]:
  41. raises(NotImplementedError, lambda: pickle.dumps(a, protocol))
  42. protocols = [2, copy.copy, copy.deepcopy, 3, 4]
  43. if cloudpickle:
  44. protocols.extend([cloudpickle])
  45. for protocol in protocols:
  46. if protocol in exclude:
  47. continue
  48. if callable(protocol):
  49. if isinstance(a, BasicMeta):
  50. # Classes can't be copied, but that's okay.
  51. continue
  52. b = protocol(a)
  53. elif inspect.ismodule(protocol):
  54. b = protocol.loads(protocol.dumps(a))
  55. else:
  56. b = pickle.loads(pickle.dumps(a, protocol))
  57. d1 = dir(a)
  58. d2 = dir(b)
  59. assert set(d1) == set(d2)
  60. if not check_attr:
  61. continue
  62. def c(a, b, d):
  63. for i in d:
  64. if i in excluded_attrs:
  65. continue
  66. if not hasattr(a, i):
  67. continue
  68. attr = getattr(a, i)
  69. if not hasattr(attr, "__call__"):
  70. assert hasattr(b, i), i
  71. assert getattr(b, i) == attr, "%s != %s, protocol: %s" % (getattr(b, i), attr, protocol)
  72. c(a, b, d1)
  73. c(b, a, d2)
  74. #================== core =========================
  75. def test_core_basic():
  76. for c in (Atom, Atom(),
  77. Basic, Basic(),
  78. # XXX: dynamically created types are not picklable
  79. # BasicMeta, BasicMeta("test", (), {}),
  80. SingletonRegistry, S):
  81. check(c)
  82. def test_core_Str():
  83. check(Str('x'))
  84. def test_core_symbol():
  85. # make the Symbol a unique name that doesn't class with any other
  86. # testing variable in this file since after this test the symbol
  87. # having the same name will be cached as noncommutative
  88. for c in (Dummy, Dummy("x", commutative=False), Symbol,
  89. Symbol("_issue_3130", commutative=False), Wild, Wild("x")):
  90. check(c)
  91. def test_core_numbers():
  92. for c in (Integer(2), Rational(2, 3), Float("1.2")):
  93. check(c)
  94. for c in (AlgebraicNumber, AlgebraicNumber(sqrt(3))):
  95. check(c, check_attr=False)
  96. def test_core_float_copy():
  97. # See gh-7457
  98. y = Symbol("x") + 1.0
  99. check(y) # does not raise TypeError ("argument is not an mpz")
  100. def test_core_relational():
  101. x = Symbol("x")
  102. y = Symbol("y")
  103. for c in (Equality, Equality(x, y), GreaterThan, GreaterThan(x, y),
  104. LessThan, LessThan(x, y), Relational, Relational(x, y),
  105. StrictGreaterThan, StrictGreaterThan(x, y), StrictLessThan,
  106. StrictLessThan(x, y), Unequality, Unequality(x, y)):
  107. check(c)
  108. def test_core_add():
  109. x = Symbol("x")
  110. for c in (Add, Add(x, 4)):
  111. check(c)
  112. def test_core_mul():
  113. x = Symbol("x")
  114. for c in (Mul, Mul(x, 4)):
  115. check(c)
  116. def test_core_power():
  117. x = Symbol("x")
  118. for c in (Pow, Pow(x, 4)):
  119. check(c)
  120. def test_core_function():
  121. x = Symbol("x")
  122. for f in (Derivative, Derivative(x), Function, FunctionClass, Lambda,
  123. WildFunction):
  124. check(f)
  125. def test_core_undefinedfunctions():
  126. f = Function("f")
  127. # Full XFAILed test below
  128. exclude = list(range(5))
  129. # https://github.com/cloudpipe/cloudpickle/issues/65
  130. # https://github.com/cloudpipe/cloudpickle/issues/190
  131. exclude.append(cloudpickle)
  132. check(f, exclude=exclude)
  133. @XFAIL
  134. def test_core_undefinedfunctions_fail():
  135. # This fails because f is assumed to be a class at sympy.basic.function.f
  136. f = Function("f")
  137. check(f)
  138. def test_core_interval():
  139. for c in (Interval, Interval(0, 2)):
  140. check(c)
  141. def test_core_multidimensional():
  142. for c in (vectorize, vectorize(0)):
  143. check(c)
  144. def test_Singletons():
  145. protocols = [0, 1, 2, 3, 4]
  146. copiers = [copy.copy, copy.deepcopy]
  147. copiers += [lambda x: pickle.loads(pickle.dumps(x, proto))
  148. for proto in protocols]
  149. if cloudpickle:
  150. copiers += [lambda x: cloudpickle.loads(cloudpickle.dumps(x))]
  151. for obj in (Integer(-1), Integer(0), Integer(1), Rational(1, 2), pi, E, I,
  152. oo, -oo, zoo, nan, S.GoldenRatio, S.TribonacciConstant,
  153. S.EulerGamma, S.Catalan, S.EmptySet, S.IdentityFunction):
  154. for func in copiers:
  155. assert func(obj) is obj
  156. #================== functions ===================
  157. from sympy.functions import (Piecewise, lowergamma, acosh, chebyshevu,
  158. chebyshevt, ln, chebyshevt_root, legendre, Heaviside, bernoulli, coth,
  159. tanh, assoc_legendre, sign, arg, asin, DiracDelta, re, rf, Abs,
  160. uppergamma, binomial, sinh, cos, cot, acos, acot, gamma, bell,
  161. hermite, harmonic, LambertW, zeta, log, factorial, asinh, acoth, cosh,
  162. dirichlet_eta, Eijk, loggamma, erf, ceiling, im, fibonacci,
  163. tribonacci, conjugate, tan, chebyshevu_root, floor, atanh, sqrt, sin,
  164. atan, ff, lucas, atan2, polygamma, exp)
  165. def test_functions():
  166. one_var = (acosh, ln, Heaviside, factorial, bernoulli, coth, tanh,
  167. sign, arg, asin, DiracDelta, re, Abs, sinh, cos, cot, acos, acot,
  168. gamma, bell, harmonic, LambertW, zeta, log, factorial, asinh,
  169. acoth, cosh, dirichlet_eta, loggamma, erf, ceiling, im, fibonacci,
  170. tribonacci, conjugate, tan, floor, atanh, sin, atan, lucas, exp)
  171. two_var = (rf, ff, lowergamma, chebyshevu, chebyshevt, binomial,
  172. atan2, polygamma, hermite, legendre, uppergamma)
  173. x, y, z = symbols("x,y,z")
  174. others = (chebyshevt_root, chebyshevu_root, Eijk(x, y, z),
  175. Piecewise( (0, x < -1), (x**2, x <= 1), (x**3, True)),
  176. assoc_legendre)
  177. for cls in one_var:
  178. check(cls)
  179. c = cls(x)
  180. check(c)
  181. for cls in two_var:
  182. check(cls)
  183. c = cls(x, y)
  184. check(c)
  185. for cls in others:
  186. check(cls)
  187. #================== geometry ====================
  188. from sympy.geometry.entity import GeometryEntity
  189. from sympy.geometry.point import Point
  190. from sympy.geometry.ellipse import Circle, Ellipse
  191. from sympy.geometry.line import Line, LinearEntity, Ray, Segment
  192. from sympy.geometry.polygon import Polygon, RegularPolygon, Triangle
  193. def test_geometry():
  194. p1 = Point(1, 2)
  195. p2 = Point(2, 3)
  196. p3 = Point(0, 0)
  197. p4 = Point(0, 1)
  198. for c in (
  199. GeometryEntity, GeometryEntity(), Point, p1, Circle, Circle(p1, 2),
  200. Ellipse, Ellipse(p1, 3, 4), Line, Line(p1, p2), LinearEntity,
  201. LinearEntity(p1, p2), Ray, Ray(p1, p2), Segment, Segment(p1, p2),
  202. Polygon, Polygon(p1, p2, p3, p4), RegularPolygon,
  203. RegularPolygon(p1, 4, 5), Triangle, Triangle(p1, p2, p3)):
  204. check(c, check_attr=False)
  205. #================== integrals ====================
  206. from sympy.integrals.integrals import Integral
  207. def test_integrals():
  208. x = Symbol("x")
  209. for c in (Integral, Integral(x)):
  210. check(c)
  211. #==================== logic =====================
  212. from sympy.core.logic import Logic
  213. def test_logic():
  214. for c in (Logic, Logic(1)):
  215. check(c)
  216. #================== matrices ====================
  217. from sympy.matrices import Matrix, SparseMatrix
  218. def test_matrices():
  219. for c in (Matrix, Matrix([1, 2, 3]), SparseMatrix, SparseMatrix([[1, 2], [3, 4]])):
  220. check(c)
  221. #================== ntheory =====================
  222. from sympy.ntheory.generate import Sieve
  223. def test_ntheory():
  224. for c in (Sieve, Sieve()):
  225. check(c)
  226. #================== physics =====================
  227. from sympy.physics.paulialgebra import Pauli
  228. from sympy.physics.units import Unit
  229. def test_physics():
  230. for c in (Unit, meter, Pauli, Pauli(1)):
  231. check(c)
  232. #================== plotting ====================
  233. # XXX: These tests are not complete, so XFAIL them
  234. @XFAIL
  235. def test_plotting():
  236. from sympy.plotting.pygletplot.color_scheme import ColorGradient, ColorScheme
  237. from sympy.plotting.pygletplot.managed_window import ManagedWindow
  238. from sympy.plotting.plot import Plot, ScreenShot
  239. from sympy.plotting.pygletplot.plot_axes import PlotAxes, PlotAxesBase, PlotAxesFrame, PlotAxesOrdinate
  240. from sympy.plotting.pygletplot.plot_camera import PlotCamera
  241. from sympy.plotting.pygletplot.plot_controller import PlotController
  242. from sympy.plotting.pygletplot.plot_curve import PlotCurve
  243. from sympy.plotting.pygletplot.plot_interval import PlotInterval
  244. from sympy.plotting.pygletplot.plot_mode import PlotMode
  245. from sympy.plotting.pygletplot.plot_modes import Cartesian2D, Cartesian3D, Cylindrical, \
  246. ParametricCurve2D, ParametricCurve3D, ParametricSurface, Polar, Spherical
  247. from sympy.plotting.pygletplot.plot_object import PlotObject
  248. from sympy.plotting.pygletplot.plot_surface import PlotSurface
  249. from sympy.plotting.pygletplot.plot_window import PlotWindow
  250. for c in (
  251. ColorGradient, ColorGradient(0.2, 0.4), ColorScheme, ManagedWindow,
  252. ManagedWindow, Plot, ScreenShot, PlotAxes, PlotAxesBase,
  253. PlotAxesFrame, PlotAxesOrdinate, PlotCamera, PlotController,
  254. PlotCurve, PlotInterval, PlotMode, Cartesian2D, Cartesian3D,
  255. Cylindrical, ParametricCurve2D, ParametricCurve3D,
  256. ParametricSurface, Polar, Spherical, PlotObject, PlotSurface,
  257. PlotWindow):
  258. check(c)
  259. @XFAIL
  260. def test_plotting2():
  261. #from sympy.plotting.color_scheme import ColorGradient
  262. from sympy.plotting.pygletplot.color_scheme import ColorScheme
  263. #from sympy.plotting.managed_window import ManagedWindow
  264. from sympy.plotting.plot import Plot
  265. #from sympy.plotting.plot import ScreenShot
  266. from sympy.plotting.pygletplot.plot_axes import PlotAxes
  267. #from sympy.plotting.plot_axes import PlotAxesBase, PlotAxesFrame, PlotAxesOrdinate
  268. #from sympy.plotting.plot_camera import PlotCamera
  269. #from sympy.plotting.plot_controller import PlotController
  270. #from sympy.plotting.plot_curve import PlotCurve
  271. #from sympy.plotting.plot_interval import PlotInterval
  272. #from sympy.plotting.plot_mode import PlotMode
  273. #from sympy.plotting.plot_modes import Cartesian2D, Cartesian3D, Cylindrical, \
  274. # ParametricCurve2D, ParametricCurve3D, ParametricSurface, Polar, Spherical
  275. #from sympy.plotting.plot_object import PlotObject
  276. #from sympy.plotting.plot_surface import PlotSurface
  277. # from sympy.plotting.plot_window import PlotWindow
  278. check(ColorScheme("rainbow"))
  279. check(Plot(1, visible=False))
  280. check(PlotAxes())
  281. #================== polys =======================
  282. from sympy.polys.domains.integerring import ZZ
  283. from sympy.polys.domains.rationalfield import QQ
  284. from sympy.polys.orderings import lex
  285. from sympy.polys.polytools import Poly
  286. def test_pickling_polys_polytools():
  287. from sympy.polys.polytools import PurePoly
  288. # from sympy.polys.polytools import GroebnerBasis
  289. x = Symbol('x')
  290. for c in (Poly, Poly(x, x)):
  291. check(c)
  292. for c in (PurePoly, PurePoly(x)):
  293. check(c)
  294. # TODO: fix pickling of Options class (see GroebnerBasis._options)
  295. # for c in (GroebnerBasis, GroebnerBasis([x**2 - 1], x, order=lex)):
  296. # check(c)
  297. def test_pickling_polys_polyclasses():
  298. from sympy.polys.polyclasses import DMP, DMF, ANP
  299. for c in (DMP, DMP([[ZZ(1)], [ZZ(2)], [ZZ(3)]], ZZ)):
  300. check(c)
  301. for c in (DMF, DMF(([ZZ(1), ZZ(2)], [ZZ(1), ZZ(3)]), ZZ)):
  302. check(c)
  303. for c in (ANP, ANP([QQ(1), QQ(2)], [QQ(1), QQ(2), QQ(3)], QQ)):
  304. check(c)
  305. @XFAIL
  306. def test_pickling_polys_rings():
  307. # NOTE: can't use protocols < 2 because we have to execute __new__ to
  308. # make sure caching of rings works properly.
  309. from sympy.polys.rings import PolyRing
  310. ring = PolyRing("x,y,z", ZZ, lex)
  311. for c in (PolyRing, ring):
  312. check(c, exclude=[0, 1])
  313. for c in (ring.dtype, ring.one):
  314. check(c, exclude=[0, 1], check_attr=False) # TODO: Py3k
  315. def test_pickling_polys_fields():
  316. pass
  317. # NOTE: can't use protocols < 2 because we have to execute __new__ to
  318. # make sure caching of fields works properly.
  319. # from sympy.polys.fields import FracField
  320. # field = FracField("x,y,z", ZZ, lex)
  321. # TODO: AssertionError: assert id(obj) not in self.memo
  322. # for c in (FracField, field):
  323. # check(c, exclude=[0, 1])
  324. # TODO: AssertionError: assert id(obj) not in self.memo
  325. # for c in (field.dtype, field.one):
  326. # check(c, exclude=[0, 1])
  327. def test_pickling_polys_elements():
  328. from sympy.polys.domains.pythonrational import PythonRational
  329. #from sympy.polys.domains.pythonfinitefield import PythonFiniteField
  330. #from sympy.polys.domains.mpelements import MPContext
  331. for c in (PythonRational, PythonRational(1, 7)):
  332. check(c)
  333. #gf = PythonFiniteField(17)
  334. # TODO: fix pickling of ModularInteger
  335. # for c in (gf.dtype, gf(5)):
  336. # check(c)
  337. #mp = MPContext()
  338. # TODO: fix pickling of RealElement
  339. # for c in (mp.mpf, mp.mpf(1.0)):
  340. # check(c)
  341. # TODO: fix pickling of ComplexElement
  342. # for c in (mp.mpc, mp.mpc(1.0, -1.5)):
  343. # check(c)
  344. def test_pickling_polys_domains():
  345. # from sympy.polys.domains.pythonfinitefield import PythonFiniteField
  346. from sympy.polys.domains.pythonintegerring import PythonIntegerRing
  347. from sympy.polys.domains.pythonrationalfield import PythonRationalField
  348. # TODO: fix pickling of ModularInteger
  349. # for c in (PythonFiniteField, PythonFiniteField(17)):
  350. # check(c)
  351. for c in (PythonIntegerRing, PythonIntegerRing()):
  352. check(c, check_attr=False)
  353. for c in (PythonRationalField, PythonRationalField()):
  354. check(c, check_attr=False)
  355. if HAS_GMPY:
  356. # from sympy.polys.domains.gmpyfinitefield import GMPYFiniteField
  357. from sympy.polys.domains.gmpyintegerring import GMPYIntegerRing
  358. from sympy.polys.domains.gmpyrationalfield import GMPYRationalField
  359. # TODO: fix pickling of ModularInteger
  360. # for c in (GMPYFiniteField, GMPYFiniteField(17)):
  361. # check(c)
  362. for c in (GMPYIntegerRing, GMPYIntegerRing()):
  363. check(c, check_attr=False)
  364. for c in (GMPYRationalField, GMPYRationalField()):
  365. check(c, check_attr=False)
  366. #from sympy.polys.domains.realfield import RealField
  367. #from sympy.polys.domains.complexfield import ComplexField
  368. from sympy.polys.domains.algebraicfield import AlgebraicField
  369. #from sympy.polys.domains.polynomialring import PolynomialRing
  370. #from sympy.polys.domains.fractionfield import FractionField
  371. from sympy.polys.domains.expressiondomain import ExpressionDomain
  372. # TODO: fix pickling of RealElement
  373. # for c in (RealField, RealField(100)):
  374. # check(c)
  375. # TODO: fix pickling of ComplexElement
  376. # for c in (ComplexField, ComplexField(100)):
  377. # check(c)
  378. for c in (AlgebraicField, AlgebraicField(QQ, sqrt(3))):
  379. check(c, check_attr=False)
  380. # TODO: AssertionError
  381. # for c in (PolynomialRing, PolynomialRing(ZZ, "x,y,z")):
  382. # check(c)
  383. # TODO: AttributeError: 'PolyElement' object has no attribute 'ring'
  384. # for c in (FractionField, FractionField(ZZ, "x,y,z")):
  385. # check(c)
  386. for c in (ExpressionDomain, ExpressionDomain()):
  387. check(c, check_attr=False)
  388. def test_pickling_polys_orderings():
  389. from sympy.polys.orderings import (LexOrder, GradedLexOrder,
  390. ReversedGradedLexOrder, InverseOrder)
  391. # from sympy.polys.orderings import ProductOrder
  392. for c in (LexOrder, LexOrder()):
  393. check(c)
  394. for c in (GradedLexOrder, GradedLexOrder()):
  395. check(c)
  396. for c in (ReversedGradedLexOrder, ReversedGradedLexOrder()):
  397. check(c)
  398. # TODO: Argh, Python is so naive. No lambdas nor inner function support in
  399. # pickling module. Maybe someone could figure out what to do with this.
  400. #
  401. # for c in (ProductOrder, ProductOrder((LexOrder(), lambda m: m[:2]),
  402. # (GradedLexOrder(), lambda m: m[2:]))):
  403. # check(c)
  404. for c in (InverseOrder, InverseOrder(LexOrder())):
  405. check(c)
  406. def test_pickling_polys_monomials():
  407. from sympy.polys.monomials import MonomialOps, Monomial
  408. x, y, z = symbols("x,y,z")
  409. for c in (MonomialOps, MonomialOps(3)):
  410. check(c)
  411. for c in (Monomial, Monomial((1, 2, 3), (x, y, z))):
  412. check(c)
  413. def test_pickling_polys_errors():
  414. from sympy.polys.polyerrors import (HeuristicGCDFailed,
  415. HomomorphismFailed, IsomorphismFailed, ExtraneousFactors,
  416. EvaluationFailed, RefinementFailed, CoercionFailed, NotInvertible,
  417. NotReversible, NotAlgebraic, DomainError, PolynomialError,
  418. UnificationFailed, GeneratorsError, GeneratorsNeeded,
  419. UnivariatePolynomialError, MultivariatePolynomialError, OptionError,
  420. FlagError)
  421. # from sympy.polys.polyerrors import (ExactQuotientFailed,
  422. # OperationNotSupported, ComputationFailed, PolificationFailed)
  423. # x = Symbol('x')
  424. # TODO: TypeError: __init__() takes at least 3 arguments (1 given)
  425. # for c in (ExactQuotientFailed, ExactQuotientFailed(x, 3*x, ZZ)):
  426. # check(c)
  427. # TODO: TypeError: can't pickle instancemethod objects
  428. # for c in (OperationNotSupported, OperationNotSupported(Poly(x), Poly.gcd)):
  429. # check(c)
  430. for c in (HeuristicGCDFailed, HeuristicGCDFailed()):
  431. check(c)
  432. for c in (HomomorphismFailed, HomomorphismFailed()):
  433. check(c)
  434. for c in (IsomorphismFailed, IsomorphismFailed()):
  435. check(c)
  436. for c in (ExtraneousFactors, ExtraneousFactors()):
  437. check(c)
  438. for c in (EvaluationFailed, EvaluationFailed()):
  439. check(c)
  440. for c in (RefinementFailed, RefinementFailed()):
  441. check(c)
  442. for c in (CoercionFailed, CoercionFailed()):
  443. check(c)
  444. for c in (NotInvertible, NotInvertible()):
  445. check(c)
  446. for c in (NotReversible, NotReversible()):
  447. check(c)
  448. for c in (NotAlgebraic, NotAlgebraic()):
  449. check(c)
  450. for c in (DomainError, DomainError()):
  451. check(c)
  452. for c in (PolynomialError, PolynomialError()):
  453. check(c)
  454. for c in (UnificationFailed, UnificationFailed()):
  455. check(c)
  456. for c in (GeneratorsError, GeneratorsError()):
  457. check(c)
  458. for c in (GeneratorsNeeded, GeneratorsNeeded()):
  459. check(c)
  460. # TODO: PicklingError: Can't pickle <function <lambda> at 0x38578c0>: it's not found as __main__.<lambda>
  461. # for c in (ComputationFailed, ComputationFailed(lambda t: t, 3, None)):
  462. # check(c)
  463. for c in (UnivariatePolynomialError, UnivariatePolynomialError()):
  464. check(c)
  465. for c in (MultivariatePolynomialError, MultivariatePolynomialError()):
  466. check(c)
  467. # TODO: TypeError: __init__() takes at least 3 arguments (1 given)
  468. # for c in (PolificationFailed, PolificationFailed({}, x, x, False)):
  469. # check(c)
  470. for c in (OptionError, OptionError()):
  471. check(c)
  472. for c in (FlagError, FlagError()):
  473. check(c)
  474. #def test_pickling_polys_options():
  475. #from sympy.polys.polyoptions import Options
  476. # TODO: fix pickling of `symbols' flag
  477. # for c in (Options, Options((), dict(domain='ZZ', polys=False))):
  478. # check(c)
  479. # TODO: def test_pickling_polys_rootisolation():
  480. # RealInterval
  481. # ComplexInterval
  482. def test_pickling_polys_rootoftools():
  483. from sympy.polys.rootoftools import CRootOf, RootSum
  484. x = Symbol('x')
  485. f = x**3 + x + 3
  486. for c in (CRootOf, CRootOf(f, 0)):
  487. check(c)
  488. for c in (RootSum, RootSum(f, exp)):
  489. check(c)
  490. #================== printing ====================
  491. from sympy.printing.latex import LatexPrinter
  492. from sympy.printing.mathml import MathMLContentPrinter, MathMLPresentationPrinter
  493. from sympy.printing.pretty.pretty import PrettyPrinter
  494. from sympy.printing.pretty.stringpict import prettyForm, stringPict
  495. from sympy.printing.printer import Printer
  496. from sympy.printing.python import PythonPrinter
  497. def test_printing():
  498. for c in (LatexPrinter, LatexPrinter(), MathMLContentPrinter,
  499. MathMLPresentationPrinter, PrettyPrinter, prettyForm, stringPict,
  500. stringPict("a"), Printer, Printer(), PythonPrinter,
  501. PythonPrinter()):
  502. check(c)
  503. @XFAIL
  504. def test_printing1():
  505. check(MathMLContentPrinter())
  506. @XFAIL
  507. def test_printing2():
  508. check(MathMLPresentationPrinter())
  509. @XFAIL
  510. def test_printing3():
  511. check(PrettyPrinter())
  512. #================== series ======================
  513. from sympy.series.limits import Limit
  514. from sympy.series.order import Order
  515. def test_series():
  516. e = Symbol("e")
  517. x = Symbol("x")
  518. for c in (Limit, Limit(e, x, 1), Order, Order(e)):
  519. check(c)
  520. #================== concrete ==================
  521. from sympy.concrete.products import Product
  522. from sympy.concrete.summations import Sum
  523. def test_concrete():
  524. x = Symbol("x")
  525. for c in (Product, Product(x, (x, 2, 4)), Sum, Sum(x, (x, 2, 4))):
  526. check(c)
  527. def test_deprecation_warning():
  528. w = SymPyDeprecationWarning("message", deprecated_since_version='1.0', active_deprecations_target="active-deprecations")
  529. check(w)
  530. def test_issue_18438():
  531. assert pickle.loads(pickle.dumps(S.Half)) == 1/2
  532. #================= old pickles =================
  533. def test_unpickle_from_older_versions():
  534. data = (
  535. b'\x80\x04\x95^\x00\x00\x00\x00\x00\x00\x00\x8c\x10sympy.core.power'
  536. b'\x94\x8c\x03Pow\x94\x93\x94\x8c\x12sympy.core.numbers\x94\x8c'
  537. b'\x07Integer\x94\x93\x94K\x02\x85\x94R\x94}\x94bh\x03\x8c\x04Half'
  538. b'\x94\x93\x94)R\x94}\x94b\x86\x94R\x94}\x94b.'
  539. )
  540. assert pickle.loads(data) == sqrt(2)