Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
self.mock_popen = testfixtures.popen.MockPopen()
self.r = testfixtures.Replacer()
self.r.replace('subprocess.Popen', self.mock_popen)
self.addCleanup(self.r.restore)
def test_timeout(self):
source, drain = socket.socketpair()
try:
with testfixtures.Replacer() as r:
mock_time = testfixtures.test_time(delta=0.1,
delta_type='seconds')
r.replace('streamexpect.time.time', mock_time)
adapter = PollingSocketStreamAdapter(drain)
with self.assertRaises(ExpectTimeout):
adapter.poll(0.01)
finally:
source.close()
drain.close()
def setUp(self):
def get_source():
return 'default_source'
self.r = Replacer()
self.r.replace('configurator._api.get_source', get_source)
self.r.replace('configurator._section.get_source', get_source)
log_path = join(root_path, 'logs')
args = [
"--log_dir", log_path, "--app_gen_output_dir", root_path, "--test_build_only", "--switch_xcode_versions",
"--full_clean"
]
# we need the unused named variable for mocking purposes
# noinspection PyUnusedLocal
def command_callable(command, stdin):
if 'cloc' in command:
return PopenBehaviour(stdout=cloc_out)
elif 'xcodebuild -version' in command:
return PopenBehaviour(stdout=b'Xcode 10.0\nBuild version 10A255\n')
return PopenBehaviour(stdout=b'test_out', stderr=b'test_error')
with testfixtures.Replacer() as rep:
mock_popen = MockPopen()
rep.replace('subprocess.Popen', mock_popen)
mock_popen.set_default(behaviour=command_callable)
with mock.patch('distutils.spawn.find_executable') as mock_find:
mock_find.return_value = '/bin/ls' # A non empty return value basically means "I found that executable"
CommandLineMultisuite().main(args)
self.assertGreater(os.listdir(app_path), 0)
self.verify_genproj('MockLib53', 101, app_path)
def run(argv, expected_output=''):
with Replacer() as r:
r.replace('sys.argv', ['x']+argv)
r.replace('picky.main.conda_env_export',
mock_conda_env_export)
with OutputCapture() as output:
rc = main()
output.compare(expected_output)
return rc
def run_main(self, args=(), output='', return_code=0):
# so we don't leave log handlers lying around...
# ...level is so that we check the log level is correctly set
# in setup_logging
with LogCapture(level=100):
with Replacer() as r:
# set argv
argv = ['x'] + args
r.replace('sys.argv', argv)
r.replace('picky.main.datetime', test_datetime(2001, 1, 2, 3, 4, 5))
# set PATH env variable
r.replace('os.environ.PATH', self.path)
# change to tempdir
cwd = os.getcwd()
try:
os.chdir(self.dir.path)
# get the exit code
with ShouldRaise(SystemExit) as s:
# capture output
with OutputCapture() as actual:
main()
finally:
def test_timeout(self):
with testfixtures.Replacer() as r:
mock_time = testfixtures.test_time(delta=0.1, delta_type='seconds')
r.replace('streamexpect.time.time', mock_time)
r.replace('streamexpect.time.sleep', lambda _: None)
stream = EmptyStream()
adapter = PollingStreamAdapter(stream)
with self.assertRaises(ExpectTimeout):
adapter.poll(1)