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)')
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)')
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)
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 )
def test_reexec_windows_fails(self, exec_patch): with pytest.raises(RuntimeError): libfaketime.reexec_if_needed()
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')
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')
def pytest_configure(): reexec_if_needed() logging.getLogger('slouch').addHandler(logging.NullHandler())
def pytest_configure(): reexec_if_needed()
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)
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])
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:
def pytest_configure(): libfaketime.reexec_if_needed() _, env_additions = libfaketime.get_reload_information() os.environ.update(env_additions)
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)