コード例 #1
0
ファイル: __init__.py プロジェクト: YPlan/python-libfaketime
def setup_package():
    ext_dir = os.path.dirname(list(libfaketime._lib_addition[sys.platform[:5]].values())[0])
    ext_dir = os.path.join(ext_dir, '..')
    subprocess.check_call(['make', '-C', ext_dir])

    libfaketime.reexec_if_needed()

    print('(re-execed and compiled prior to test run)')
コード例 #2
0
def setup_package():
    ext_dir = os.path.dirname(
        list(libfaketime._lib_addition[sys.platform[:5]].values())[0])
    ext_dir = os.path.join(ext_dir, '..')
    subprocess.check_call(['make', '-C', ext_dir])

    libfaketime.reexec_if_needed()

    print('(re-execed and compiled prior to test run)')
コード例 #3
0
    def _assert_successful_reexec(self, exec_patch):
        expected_environ = os.environ.copy()
        expected_environ.update(libfaketime.get_reload_information()[1])

        libfaketime.reexec_if_needed()

        exec_patch.assert_called_once_with(sys.executable,
                                           [sys.executable] + sys.argv,
                                           expected_environ)
コード例 #4
0
    def _assert_successful_reexec(self, exec_patch):
        expected_environ = os.environ.copy()
        expected_environ.update(libfaketime.get_reload_information()[1])

        libfaketime.reexec_if_needed()

        exec_patch.assert_called_once_with(
            sys.executable, [sys.executable] + sys.argv, expected_environ
        )
コード例 #5
0
 def test_reexec_windows_fails(self, exec_patch):
     with pytest.raises(RuntimeError):
         libfaketime.reexec_if_needed()
コード例 #6
0
import os
import unittest
from libfaketime import fake_time, reexec_if_needed
import shutil
from datetime import datetime
from ftpretty import ftpretty
from compat import PY2
from .mock_ftp import MockFTP

reexec_if_needed()


class FtprettyTestCase(unittest.TestCase):
    def setUp(self):
        self.mock_ftp = MockFTP()
        self.pretty = ftpretty(None, None, None, ftp_conn=self.mock_ftp)

    def test_cd(self):
        self.pretty.cd('photos/nature/mountains')
        self.assertEqual(self.pretty.pwd(), 'photos/nature/mountains')
        self.pretty._set_exists(False)
        self.assertRaises(Exception, self.pretty.cd('blah'))

    def test_cd_up(self):
        self.pretty.cd('photos/nature/mountains')
        self.pretty.cd('../..')
        self.assertEqual(self.pretty.pwd(), 'photos')

    def test_make_directory(self):
        self.pretty.cd('photos')
        self.pretty.mkdir('family')
コード例 #7
0
ファイル: benchmark.py プロジェクト: YPlan/python-libfaketime
from freezegun import freeze_time as freezegun_fake_time


def sample(faker):
    start = time.clock()

    with faker(datetime.datetime.now()):
        datetime.datetime.now()

    datetime.datetime.now()

    return time.clock() - start

if __name__ == '__main__':

    if len(sys.argv) > 1 and sys.argv[1] == 'freezegun':
        faker = freezegun_fake_time
    else:
        faker = lft_fake_time
        reexec_if_needed()

    iterations = 1000

    print("timing %s executions of %s" % (iterations, faker))

    sum = 0
    for _ in range(iterations):
        sum += sample(faker)

    print(sum, 'seconds')
コード例 #8
0
def pytest_configure():
    reexec_if_needed()
    logging.getLogger('slouch').addHandler(logging.NullHandler())
コード例 #9
0
def pytest_configure():
    reexec_if_needed()
コード例 #10
0
from pyiso import client_factory, BALANCING_AUTHORITIES
from pyiso.base import BaseClient
from pyiso.eu import EUClient
from unittest import TestCase
from datetime import datetime, timedelta
import unittest
import pytz
import mock
import libfaketime
libfaketime.reexec_if_needed()


class TestBaseLoad(TestCase):
    def setUp(self):
        # set up expected values from base client
        bc = BaseClient()
        self.MARKET_CHOICES = bc.MARKET_CHOICES
        self.FREQUENCY_CHOICES = bc.FREQUENCY_CHOICES

        # set up other expected values
        self.BA_CHOICES = BALANCING_AUTHORITIES.keys()

    def _run_test(self, ba_name, expect_data=True, tol_min=0, **kwargs):
        # set up
        c = client_factory(ba_name)
        # get data
        data = c.get_load(**kwargs)

        # test number
        if expect_data:
            self.assertGreaterEqual(len(data), 1)
コード例 #11
0
ファイル: __init__.py プロジェクト: dvl/python-libfaketime
def setup_package():
    libfaketime.reexec_if_needed()

    ext_dir = os.path.dirname(libfaketime._lib_addition[sys.platform[:5]].values()[0])
    ext_dir = os.path.join(ext_dir, '..')
    subprocess.check_call(['make', '-C', ext_dir])
コード例 #12
0
ファイル: test_load.py プロジェクト: avances123/pyiso
from pyiso import client_factory, BALANCING_AUTHORITIES
from pyiso.base import BaseClient
from pyiso.eu import EUClient
from unittest import TestCase
from datetime import datetime, timedelta
import unittest
import pytz
import mock
import libfaketime
libfaketime.reexec_if_needed()


class TestBaseLoad(TestCase):
    def setUp(self):
        # set up expected values from base client
        bc = BaseClient()
        self.MARKET_CHOICES = bc.MARKET_CHOICES
        self.FREQUENCY_CHOICES = bc.FREQUENCY_CHOICES

        # set up other expected values
        self.BA_CHOICES = BALANCING_AUTHORITIES.keys()

    def _run_test(self, ba_name, expect_data=True, tol_min=0, **kwargs):
        # set up
        c = client_factory(ba_name)

        # get data
        data = c.get_load(**kwargs)

        # test number
        if expect_data:
コード例 #13
0
def pytest_configure():
    libfaketime.reexec_if_needed()
    _, env_additions = libfaketime.get_reload_information()
    os.environ.update(env_additions)
コード例 #14
0
class TestWpsParser(TestCase):
    reexec_if_needed()

    def setUp(self):
        self.wps = WpsParser()
        self.logger = logging.getLogger()
        self.logger.setLevel(logging.INFO)
        self.logger.addHandler(logging.StreamHandler())

    def test_clear(self):
        expected_command = {
            'commandType': CommandType.CLEAR,
        }
        command = self.wps.parse("  clear  ")
        self.assertEqual(expected_command, command)

    @fake_time('1970-12-14 13:05:15')
    def test_parse_set_status_from_to(self):
        expected_command = {
            'commandType': CommandType.SET,
            'status': 'sick',
            'from_date': datetime(1970, 12, 14 + 1, 0, 0, 0),
            'to_date': datetime(1970, 12, 14 + 3, 23, 59, 59, 999999)
        }
        command = self.wps.parse("sick from tomorrow to in 3 days")
        self.assertEqual(expected_command, command)

    @fake_time('1970-12-10 13:05:15')
    def test_parse_set_status_on(self):
        expected_command = {
            'commandType': CommandType.SET,
            'status': 'sick',
            'from_date': datetime(1970, 12, 10 + 1, 0, 0, 0),
            'to_date': datetime(1970, 12, 10 + 1, 23, 59, 59, 999999)
        }
        command = self.wps.parse("sick on tomorrow")
        self.assertEqual(expected_command, command)

    @fake_time('1970-12-10 13:05:15')
    def test_parse_set_status_on_with_time(self):
        expected_command = {
            'commandType': CommandType.SET,
            'status': 'sick',
            'from_date': datetime(1970, 12, 10 + 1, 8, 0, 0),
            'to_date': datetime(1970, 12, 10 + 1, 23, 59, 59, 999999)
        }
        command = self.wps.parse("sick on tomorrow at 8am")
        self.assertEqual(expected_command, command)

    @fake_time('1970-12-21 16:35:10')
    def test_parse_set_status(self):
        expected_command = {
            'commandType': CommandType.SET,
            'status': 'sick',
            'from_date': datetime(1970, 12, 21, 16, 35, 10),
            'to_date': datetime(1970, 12, 21, 23, 59, 59, 999999)
        }
        command = self.wps.parse("sick")
        self.assertEqual(expected_command, command)

    @fake_time('1970-12-21 16:35:10')
    def test_parse_get_status_for_multiple_users(self):
        expected_command = {
            'commandType': CommandType.GET,
            'users': ['john', 'jane'],
            'from_date': datetime(1970, 12, 21, 16, 35, 10),
            'to_date': datetime(1970, 12, 21, 23, 59, 59, 999999)
        }
        command = self.wps.parse("@john @jane")
        self.assertEqual(expected_command, command)

    @fake_time('1970-12-10 13:05:15')
    def test_parse_get_status_on(self):
        expected_command = {
            'commandType': CommandType.GET,
            'users': ['jane'],
            'from_date': datetime(1970, 12, 10 + 1, 0, 0, 0),
            'to_date': datetime(1970, 12, 10 + 1, 23, 59, 59, 999999)
        }
        command = self.wps.parse("@jane on tomorrow")
        self.assertEqual(expected_command, command)

    @fake_time('1970-12-10 13:05:15')
    def test_parse_get_status_on_with_time(self):
        expected_command = {
            'commandType': CommandType.GET,
            'users': ['jane'],
            'from_date': datetime(1970, 12, 10 + 1, 8, 0, 0),
            'to_date': datetime(1970, 12, 10 + 1, 23, 59, 59, 999999)
        }
        command = self.wps.parse("@jane on tomorrow at 8am")
        self.assertEqual(expected_command, command)

    @fake_time('1970-12-14 13:05:15')
    def test_parse_get_status_from_to(self):
        expected_command = {
            'commandType': CommandType.GET,
            'users': ['jane'],
            'from_date': datetime(1970, 12, 14 + 1, 0, 0, 0),
            'to_date': datetime(1970, 12, 14 + 3, 23, 59, 59, 999999)
        }
        command = self.wps.parse("@jane from tomorrow to in 3 days")
        self.assertEqual(expected_command, command)

    @fake_time('1970-12-21 16:35:10')
    def test_parse_get_status_for_group(self):
        expected_command = {
            'commandType': CommandType.GET_GROUP,
            'group': 'S2Z9C1ZRC'
        }
        command = self.wps.parse("<!subteam^S2Z9C1ZRC|@pku>")
        self.assertEqual(expected_command, command)