<commit_before>import signal
import unittest
import time
import multiprocessing
import os
import sys
from satella.time import measure, time_as_int, time_ms, sleep
from concurrent.futures import Future


class TestTime(unittest.TestCase):

    @unittest.skipIf('win' in sys.platform, 'Needs POSIX to run')
    def test_sleep(self):
        def runner():
            time.sleep(1)
            os.kill(os.getppid(), signal.SIGINT)

        multiprocessing.Process(target=runner).start()

        try:
            with measure() as measurement:
                sleep(3)
            self.assertGreaterEqual(measurement(), 3)
        finally:
            os.wait()

    def test_times(self):
        self.assertIsInstance(time_as_int(), int)
        self.assertIsInstance(time_ms(), int)

    def test_measure_future(self):
        future = Future()
        measurement = measure(future)
        future.set_running_or_notify_cancel()
        time.sleep(1)
        future.set_result(2)
        self.assertEqual(future.result(), 2)
        self.assertGreaterEqual(measurement(), 1)

    def test_measure(self):
        with measure() as measurement:
            time.sleep(0.5)

        self.assertGreaterEqual(measurement(), 0.5)

    def test_measure_decorator(self):
        @measure()
        def measured(measurement):
            time.sleep(0.5)
            self.assertGreaterEqual(measurement(), 0.5)
        measured()<commit_msg>more unit tests for sleep<commit_after>import signal
import unittest
import time
import multiprocessing
import os
import sys
from satella.time import measure, time_as_int, time_ms, sleep
from concurrent.futures import Future


class TestTime(unittest.TestCase):

    @unittest.skipIf('win' in sys.platform, 'Needs POSIX to run')
    def test_sleep(self):
        def runner():
            time.sleep(1)
            os.kill(os.getppid(), signal.SIGINT)

        multiprocessing.Process(target=runner).start()

        try:
            with measure() as measurement:
                sleep(3)
            self.assertGreaterEqual(measurement(), 3)
        finally:
            os.wait()

        multiprocessing.Process(target=runner).start()

        try:
            with measure() as measurement:
                sleep(3, True)
            self.assertLessEqual(measurement(), 3)
        finally:
            os.wait()

    def test_times(self):
        self.assertIsInstance(time_as_int(), int)
        self.assertIsInstance(time_ms(), int)

    def test_measure_future(self):
        future = Future()
        measurement = measure(future)
        future.set_running_or_notify_cancel()
        time.sleep(1)
        future.set_result(2)
        self.assertEqual(future.result(), 2)
        self.assertGreaterEqual(measurement(), 1)

    def test_measure(self):
        with measure() as measurement:
            time.sleep(0.5)

        self.assertGreaterEqual(measurement(), 0.5)

    def test_measure_decorator(self):
        @measure()
        def measured(measurement):
            time.sleep(0.5)
            self.assertGreaterEqual(measurement(), 0.5)
        measured()
{'fraction_non_alphanumeric': 0.10238248551191242, 'fraction_numerical': 0.0103026400515132, 'mean_word_length': 2.403066812705367, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1312014', 'n_tokens_mistral': 919, 'n_tokens_neox': 885, 'n_words': 189}