예제 #1
0
파일: test_wok.py 프로젝트: guigui64/wok
 def test_save_load(self):
     task1 = Task("task1")
     start = datetime(2019, 1, 10, 11, 11)
     end = datetime(2019, 1, 10, 11, 22)
     task1.start(dt=start)
     task1.end(dt=end)
     task2 = Task("task2")
     task3 = Task("task3")
     wok1 = Wok()
     job1 = Job("job1")
     wok1.jobs.append(job1)
     wok1.current_job_idx = 0
     job2 = Job("job2")
     wok1.jobs.append(job2)
     job1.add_task(task1)
     job1.add_task(task2)
     job2.add_task(task3)
     path = Path.cwd() / ".wok_test"
     wok1.save(dir=path)
     wok2 = Wok()
     wok2.load(dir=path)
     self.assertEqual(wok2.jobs[wok2.current_job_idx].name, "job1")
     self.assertEqual(len(wok2.jobs), 2)
     out = (path / "job1" / "task1").read_text()
     self.assertEqual(
         out, "2019-01-10T11:11:00.000000->2019-01-10T11:22:00.000000")
예제 #2
0
파일: test_task.py 프로젝트: guigui64/wok
class TestTask(unittest.TestCase):
    def setUp(self):
        self.task = Task("tested_task")

    def test_init(self):
        self.assertEqual(self.task.name, "tested_task")
        self.assertEqual(self.task.datetimes, [])
        self.assertFalse(self.task.is_running())

    def test_start(self):
        now = datetime.now()
        res = self.task.start(dt=now)
        self.assertTrue(res)
        self.assertEqual(self.task.current_datetime, now)
        self.assertTrue(self.task.is_running())

    def test_start_twice(self):
        now = datetime.now()
        res = self.task.start(dt=now)
        self.assertTrue(res)
        self.assertTrue(self.task.is_running())
        res, _ = self.task.start(dt=now)
        self.assertFalse(res)

    def test_end(self):
        res, _ = self.task.end()
        self.assertFalse(res)
        self.assertFalse(self.task.is_running())

    def test_start_end_save(self):
        start = datetime(2019, 1, 10, 11, 11)
        end = datetime(2019, 1, 10, 11, 22)
        self.task.start(dt=start)
        self.task.end(dt=end)
        self.assertEqual(self.task.datetimes, [(start, end)])
        self.assertEqual(self.task.current_datetime, None)
        out = self.task.save()
        self.assertEqual(
            out, "2019-01-10T11:11:00.000000->2019-01-10T11:22:00.000000")
        start2 = datetime(2019, 1, 10, 11, 23)
        self.task.start(dt=start2)
        self.assertEqual(self.task.datetimes, [(start, end)])
        self.assertEqual(self.task.current_datetime, start2)
        out = self.task.save()
        self.assertEqual(
            out,
            "2019-01-10T11:11:00.000000->2019-01-10T11:22:00.000000\nC:2019-01-10T11:23:00.000000",
        )

    def test_load(self):
        start = datetime(2019, 1, 10, 11, 11)
        end = datetime(2019, 1, 10, 11, 22)
        self.task.load(
            ["2019-01-10T11:11:00.000000->2019-01-10T11:22:00.000000"])
        self.assertEqual(self.task.datetimes, [(start, end)])
        self.assertEqual(self.task.current_datetime, None)
예제 #3
0
	conf = task.conf

	# get parameters

	# get N as an integer, it defaults to 100
	N = conf.get("N", 100, dtype = int)

	# get the MIN, it defaults to 1
	MIN = conf.get("MIN", 1.0, dtype = float)

	# get the MAX, it defaults to 1
	MAX = conf.get("MAX", 4.0, dtype = float)

	# get logger
	log = task.logger()
	log.debug("<<<DEBUG>>>")
	log.info("<<<INFO>>>")
	log.warn("<<<WARN>>>")
	log.error("<<<ERROR>>>")
	
	log.info("N = {}, MIN = {}, MAX = {}".format(N, MIN, MAX))

	# generate values and send them through the value_port
	for i in xrange(N):
		value = (random() * (MAX - MIN)) + MIN
		log.debug("v[{}] = {}".format(i, value))
		value_port.send(value)

task.start()