# Path: mozz/test.py
# def run_test_module(name, file):
# 	outputfile = mozz.util.python_path_basename(file) + '.out'
# 
# 	m = sys.modules[name]
# 	ldr = unittest.loader.defaultTestLoader
# 	tests = ldr.loadTestsFromModule(m)
# 
# 	with open(outputfile, 'w') as f:
# 		duper = mozz.util.IOWriteDuplicator(
# 			sys.stderr, f
# 		)
# 		unittest.runner.TextTestRunner(
# 			verbosity = 2,
# 			stream = duper
# 		).run(tests)
# 
# def abs_path(base_file, rel_path):
# 	return os.path.join(
# 		os.path.dirname(os.path.abspath(base_file)),
# 		rel_path
# 	)


import unittest
import mozz
import mozz.sig
from mozz.test import run_test_module, abs_path


class Test(unittest.TestCase):

	def test_run_exit(self):
		s = mozz.Session(abs_path(__file__, "run_exit_test.bin"), 2)

		state = [0]

		@s.on_run()
		def run(host):
			mozz.debug("cb run")
			self.assertEqual(s.iteration(), 0)
			self.assertEqual(state[0], 0)
			state[0] += 1

		def offset():
			return (s.iteration()-1)*4

		@s.on_inferior_pre()
		def inf_pre(host):
			mozz.debug("cb inf pre")
			self.assertEqual(state[0], offset() + 1)

# Path: mozz/test.py
# def run_test_module(name, file):
# 	outputfile = mozz.util.python_path_basename(file) + '.out'
# 
# 	m = sys.modules[name]
# 	ldr = unittest.loader.defaultTestLoader
# 	tests = ldr.loadTestsFromModule(m)
# 
# 	with open(outputfile, 'w') as f:
# 		duper = mozz.util.IOWriteDuplicator(
# 			sys.stderr, f
# 		)
# 		unittest.runner.TextTestRunner(
# 			verbosity = 2,
# 			stream = duper
# 		).run(tests)
# 
# def abs_path(base_file, rel_path):
# 	return os.path.join(
# 		os.path.dirname(os.path.abspath(base_file)),
# 		rel_path
# 	)


# Path: test/run_exit_test.py
import unittest
import mozz
import mozz.sig
from mozz.test import run_test_module, abs_path



class Test(unittest.TestCase):

	def test_run_exit(self):
		s = mozz.Session(abs_path(__file__, "run_exit_test.bin"), 2)

		state = [0]

		@s.on_run()
		def run(host):
			mozz.debug("cb run")
			self.assertEqual(s.iteration(), 0)
			self.assertEqual(state[0], 0)
			state[0] += 1

		def offset():
			return (s.iteration()-1)*4

		@s.on_inferior_pre()
		def inf_pre(host):
			mozz.debug("cb inf pre")
			self.assertEqual(state[0], offset() + 1)

			state[0] += 1