test_regression.py 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. #! /usr/bin/env python
  2. from testutils import McellTest
  3. from testutils import get_output_dir
  4. from testutils import cleandir
  5. from testutils import crange
  6. from testutils import RequireFileMatches
  7. from reaction_output import RequireCountConstraints
  8. from reaction_output import RequireCountEquilibrium
  9. from reaction_output import RequireCounts
  10. from reaction_output import RequireCountsPositive
  11. from reaction_output import RequireCountsLessThan
  12. import os
  13. import unittest
  14. class TestRegressions(unittest.TestCase):
  15. def test_001(self):
  16. mt = McellTest("regression", "01-remove_per_species_list_from_ht.mdl", ["-quiet"])
  17. mt.invoke(get_output_dir())
  18. def test_002(self):
  19. mt = McellTest("regression", "02-orientflipflip_rxn.mdl", ["-quiet"])
  20. mt.add_extra_check(RequireCountConstraints("counts.txt",
  21. [(1, 0, 0, 0, -1, 0), # 0
  22. (0, 1, 0, -1, 0, 0), # 0
  23. (1, 1, -1, 0, 0, 0), # 0
  24. (0, 0, 0, 1, 1, -1), # 0
  25. (0, 0, 1, 0, 0, 0), # 1000
  26. (0, 0, 0, 0, 0, 1)], # 1000
  27. [0, 0, 0, 0, 1000, 1000],
  28. header=True))
  29. mt.invoke(get_output_dir())
  30. def test_003(self):
  31. mt = McellTest("regression", "03-coincident_surfaces.mdl", ["-quiet"])
  32. mt.add_extra_check(RequireCountConstraints("cannonballs.txt",
  33. [(1, 1, -1, 0, 0, 0), # 0
  34. (0, 0, 0, 1, 1, -1), # 0
  35. (0, 0, 1, 0, 0, 0), # 500
  36. (0, 0, 0, 0, 0, 1)], # 500
  37. [0, 0, 500, 500],
  38. header=True))
  39. mt.invoke(get_output_dir())
  40. def test_004(self):
  41. mt = McellTest("regression", "04-rx_flipflip.mdl", ["-quiet"])
  42. mt.add_extra_check(RequireCountConstraints("counts.txt",
  43. [(1, 1, 0, 0, 0), # 300
  44. (0, 0, 1, 1, 0)], # 300
  45. [300, 300],
  46. header=True))
  47. mt.add_extra_check(RequireCountConstraints("counts.txt",
  48. [],
  49. [],
  50. minimums=[ 40, 40, 40, 40, 10000],
  51. maximums=[260, 260, 260, 260, 1e300],
  52. min_time=5e-5,
  53. header=True))
  54. mt.invoke(get_output_dir())
  55. def test_005(self):
  56. mt = McellTest("regression", "05-rx_dissociate_inwards.mdl", ["-quiet"])
  57. mt.add_extra_check(RequireCountConstraints("molecules.txt",
  58. [(1, 1, 0), # 1000
  59. (0, 1, -1)], # 0
  60. [1000, 0],
  61. header=True))
  62. mt.invoke(get_output_dir())
  63. def test_006(self):
  64. mt = McellTest("regression", "06-misreporting_rxn_products.mdl", ["-quiet"])
  65. mt.add_extra_check(RequireFileMatches("realout", '\s*Probability.*set for a\{0\} \+ b\{0\} -> c\{0\}', expectMaxMatches=1))
  66. mt.add_extra_check(RequireFileMatches("realout", '\s*Probability.*set for a\{0\} \+ b\{0\} -> d\{0\}', expectMaxMatches=1))
  67. mt.add_extra_check(RequireFileMatches("realout", '\s*Probability.*set for a\{0\} \+ b\{0\} -> e\{0\}', expectMaxMatches=1))
  68. mt.invoke(get_output_dir())
  69. def test_007(self):
  70. mt = McellTest("regression", "07-volvol_crash.mdl", ["-quiet"])
  71. mt.invoke(get_output_dir())
  72. def test_008(self):
  73. mt = McellTest("regression", "08-find_corresponding_region.mdl", ["-quiet"])
  74. mt.invoke(get_output_dir())
  75. def __rename(self, p1, p2):
  76. os.rename(p1, p2)
  77. def test_009(self):
  78. mt = McellTest("regression", "09-incorrect_times_in_chkpt_A.mdl", ["-quiet"])
  79. testpath = '%s/test-%04d' % (get_output_dir(), mt.testidx)
  80. mt.invoke(get_output_dir())
  81. self.__rename(os.path.join(testpath, 'cmdline.txt'), os.path.join(testpath, 'cmdline_0.txt'))
  82. self.__rename(os.path.join(testpath, 'realout'), os.path.join(testpath, 'realout.0'))
  83. self.__rename(os.path.join(testpath, 'realerr'), os.path.join(testpath, 'realerr.0'))
  84. self.__rename(os.path.join(testpath, 'stdout'), os.path.join(testpath, 'stdout.0'))
  85. self.__rename(os.path.join(testpath, 'stderr'), os.path.join(testpath, 'stderr.0'))
  86. mt.args[-1] = os.path.join(os.path.dirname(mt.args[-1]), "09-incorrect_times_in_chkpt_B.mdl")
  87. mt.invoke(get_output_dir())
  88. self.__rename(os.path.join(testpath, 'cmdline.txt'), os.path.join(testpath, 'cmdline_1.txt'))
  89. self.__rename(os.path.join(testpath, 'realout'), os.path.join(testpath, 'realout.1'))
  90. self.__rename(os.path.join(testpath, 'realerr'), os.path.join(testpath, 'realerr.1'))
  91. self.__rename(os.path.join(testpath, 'stdout'), os.path.join(testpath, 'stdout.1'))
  92. self.__rename(os.path.join(testpath, 'stderr'), os.path.join(testpath, 'stderr.1'))
  93. times = [i*1e-7 for i in range(0, 6)] + [(2*i+1)*1e-7 for i in range(3, 13)]
  94. values = zip(times, [0]*len(times))
  95. mt.add_extra_check(RequireCounts('A_World.dat', values))
  96. mt.invoke(get_output_dir())
  97. self.__rename(os.path.join(testpath, 'cmdline.txt'), os.path.join(testpath, 'cmdline_2.txt'))
  98. self.__rename(os.path.join(testpath, 'realout'), os.path.join(testpath, 'realout.2'))
  99. self.__rename(os.path.join(testpath, 'realerr'), os.path.join(testpath, 'realerr.2'))
  100. self.__rename(os.path.join(testpath, 'stdout'), os.path.join(testpath, 'stdout.2'))
  101. self.__rename(os.path.join(testpath, 'stderr'), os.path.join(testpath, 'stderr.2'))
  102. def test_010(self):
  103. mt = McellTest("regression", "10-counting_crashes_on_coincident_wall.mdl", ["-quiet"])
  104. mt.invoke(get_output_dir())
  105. def test_011(self):
  106. mt = McellTest("regression", "11-quoted_tickmark_counts_parse_error.mdl", ["-quiet"])
  107. mt.invoke(get_output_dir())
  108. def test_012(self):
  109. mt = McellTest("regression", "12-no_waypoints_counting_fail.mdl", ["-quiet"])
  110. mt.add_extra_check(RequireCountConstraints("counts.txt",
  111. # A+ ---------------------- B+ ---------------------- C+ ---------------------- A- ---------- B- ---------- C- ----------
  112. [( 1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), # 0
  113. ( 1, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), # 0
  114. ( 1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), # 0
  115. ( 1, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), # 0
  116. ( 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), # 0
  117. ( 1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), # 0
  118. ( 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), # 500
  119. ( 0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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, 0, 0, 0), # 0
  139. ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0), # 0
  140. ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0), # 0
  141. ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0), # 0
  142. ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0), # 0
  143. ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)], # 0
  144. [0]*6 + [500] + [0]*25))
  145. mt.add_extra_check(RequireCountConstraints("counts.txt",
  146. constraints=[],
  147. totals=[],
  148. min_time=9e-5,
  149. minimums=[1]*21 + [0]*12))
  150. mt.invoke(get_output_dir())
  151. def test_013(self):
  152. mt = McellTest("regression", "13-find_corresponding_region_error_crash_1.mdl", ["-quiet"])
  153. mt.add_extra_check(RequireFileMatches('realerr', r"Can't find new region corresponding to foo\.boxB,ALL for world\.bar\.rs \(copy of foo\.bar\.rs\)"))
  154. mt.set_expected_exit_code(1)
  155. mt.invoke(get_output_dir())
  156. def test_014(self):
  157. mt = McellTest("regression", "14-find_corresponding_region_error_crash_2.mdl", ["-quiet"])
  158. mt.add_extra_check(RequireFileMatches('realerr', r"Can't find new region corresponding to foo\.boxB,ALL for world\.bar\.rs \(copy of foo\.bar\.rs\)"))
  159. mt.set_expected_exit_code(1)
  160. mt.invoke(get_output_dir())
  161. def test_015(self):
  162. mt = McellTest("regression", "15-mol_grid_grid_crash.mdl", ["-quiet"])
  163. mt.invoke(get_output_dir())
  164. def test_016(self):
  165. mt = McellTest("regression", "16-mol_surf_crash.mdl", ["-quiet"])
  166. mt.invoke(get_output_dir())
  167. def test_017(self):
  168. mt = McellTest("regression", "17-uninstantiated_reference_crash.mdl", ["-quiet"])
  169. mt.add_extra_check(RequireFileMatches('realerr', r"Region neither instanced nor grouped with release site."))
  170. mt.set_expected_exit_code(1)
  171. mt.invoke(get_output_dir())
  172. def test_018(self):
  173. mt = McellTest("regression", "18-uninstantiated_reference_crash_2.mdl", ["-quiet"])
  174. mt.add_extra_check(RequireFileMatches('realerr', r"Cannot produce visualization for the uninstantiated object 'uninstantiated'"))
  175. mt.set_expected_exit_code(1)
  176. mt.invoke(get_output_dir())
  177. def test_019(self):
  178. mt = McellTest("regression", "19-enclosed_surfmol_miscount.mdl", ["-quiet"])
  179. mt.add_extra_check(RequireCountConstraints("A.dat",
  180. [(1, -1, -1)],
  181. [0],
  182. minimums=[50, 0, 0],
  183. maximums=[50, 50, 50]))
  184. mt.add_extra_check(RequireCountEquilibrium("A.dat",
  185. values=[50.0, 25.0, 25.0],
  186. tolerances=[0.0, 5.0, 5.0]))
  187. mt.invoke(get_output_dir())
  188. def test_020(self):
  189. mt = McellTest("regression", "20-reaction_null_products_crash.mdl", ["-quiet"])
  190. mt.invoke(get_output_dir())
  191. def test_021(self):
  192. mt = McellTest("regression", "21-enclosed_meshes_with_different_properties.mdl", ["-quiet"])
  193. mt.add_extra_check(RequireCounts("A.dat",[(f*1e-6, 0) for f in range (0,101)]))
  194. mt.invoke(get_output_dir())
  195. def test_022(self):
  196. mt = McellTest("regression", "22-rx_reflective_surface_bug.mdl", ["-quiet"])
  197. mt.add_extra_check(RequireCountsPositive("dat/22-rx_reflective_surface_bug/refl.dat", "# Iteration_# sm_L sm_M"))
  198. mt.invoke(get_output_dir())
  199. def test_023(self):
  200. mt = McellTest("regression", "23-walls_overlap_two_objects.mdl", ["-quiet"])
  201. mt.set_expected_exit_code(1)
  202. mt.invoke(get_output_dir())
  203. def test_024(self):
  204. mt = McellTest("regression", "24-walls_overlap_partial.mdl", ["-quiet"])
  205. mt.set_expected_exit_code(1)
  206. mt.invoke(get_output_dir())
  207. def test_025(self):
  208. mt = McellTest("regression", "25-walls_overlap_complete.mdl", ["-quiet"])
  209. mt.set_expected_exit_code(1)
  210. mt.invoke(get_output_dir())
  211. def test_026(self):
  212. mt = McellTest("regression", "26-walls_overlap_share_edge.mdl", ["-quiet"])
  213. mt.set_expected_exit_code(1)
  214. mt.invoke(get_output_dir())
  215. def test_027(self):
  216. mt = McellTest("regression", "27-walls_coincident.mdl", ["-quiet"])
  217. mt.set_expected_exit_code(1)
  218. mt.invoke(get_output_dir())
  219. def test_028(self):
  220. mt = McellTest("regression", "28-unimolecular_reaction_after_chkpt.mdl", ["-quiet"])
  221. testpath = '%s/test-%04d' % (get_output_dir(), mt.testidx)
  222. mt.invoke(get_output_dir())
  223. self.__rename(os.path.join(testpath, 'cmdline.txt'), os.path.join(testpath, 'cmdline_0.txt'))
  224. self.__rename(os.path.join(testpath, 'realout'), os.path.join(testpath, 'realout.0'))
  225. self.__rename(os.path.join(testpath, 'realerr'), os.path.join(testpath, 'realerr.0'))
  226. self.__rename(os.path.join(testpath, 'stdout'), os.path.join(testpath, 'stdout.0'))
  227. self.__rename(os.path.join(testpath, 'stderr'), os.path.join(testpath, 'stderr.0'))
  228. mt.invoke(get_output_dir())
  229. self.__rename(os.path.join(testpath, 'cmdline.txt'), os.path.join(testpath, 'cmdline_1.txt'))
  230. self.__rename(os.path.join(testpath, 'realout'), os.path.join(testpath, 'realout.1'))
  231. self.__rename(os.path.join(testpath, 'realerr'), os.path.join(testpath, 'realerr.1'))
  232. self.__rename(os.path.join(testpath, 'stdout'), os.path.join(testpath, 'stdout.1'))
  233. self.__rename(os.path.join(testpath, 'stderr'), os.path.join(testpath, 'stderr.1'))
  234. mt.add_extra_check(RequireCountsLessThan("B_World.dat", 10))
  235. def test_029(self):
  236. mt = McellTest("regression", "29-unimolecular_FOREVER.mdl", ["-quiet"])
  237. mt.add_extra_check(RequireCountEquilibrium("S1_down.dat", [10] *1,
  238. [3] *1, 1e-3, 1.5e-3, header=True))
  239. mt.invoke(get_output_dir())
  240. def suite():
  241. return unittest.makeSuite(TestRegressions, "test")