Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def do_it():
from psiturk.psiturk_shell import PsiturkNetworkShell
import psiturk.experiment_server_controller as control
from psiturk.psiturk_config import PsiturkConfig
import psiturk.experiment_server_controller
mocker.patch.object(psiturk.experiment_server_controller.ExperimentServerController, 'is_port_available', lambda *args, **kwargs: True)
mocker.patch.object(PsiturkNetworkShell,'get_intro_prompt', lambda *args, **kwargs: '')
mocker.patch.object(PsiturkNetworkShell,'update_hit_tally', lambda *args, **kwargs: None)
mocker.patch.object(PsiturkNetworkShell,'_confirm_dialog', lambda *args, **kwargs: True)
config = PsiturkConfig()
config.load_config()
server = control.ExperimentServerController(config)
launch_in_sandbox_mode = True
quiet = False
shell = PsiturkNetworkShell(
config, server,
launch_in_sandbox_mode,
quiet=quiet)
shell.persistent_history_file = None
def do_it():
from psiturk.psiturk_shell import PsiturkNetworkShell
import psiturk.experiment_server_controller as control
from psiturk.psiturk_config import PsiturkConfig
import psiturk.experiment_server_controller
mocker.patch.object(psiturk.experiment_server_controller.ExperimentServerController, 'is_port_available', lambda *args, **kwargs: True)
mocker.patch.object(PsiturkNetworkShell,'get_intro_prompt', lambda *args, **kwargs: '')
mocker.patch.object(PsiturkNetworkShell,'update_hit_tally', lambda *args, **kwargs: None)
mocker.patch.object(PsiturkNetworkShell,'_confirm_dialog', lambda *args, **kwargs: True)
config = PsiturkConfig()
config.load_config()
server = control.ExperimentServerController(config)
launch_in_sandbox_mode = True
quiet = False
shell = PsiturkNetworkShell(
config, server,
launch_in_sandbox_mode,
quiet=quiet)
shell.persistent_history_file = None
shell.echo = True
stubber.assert_no_pending_responses()
return shell
def test_awskeys_invalid(capfd, experiment_server_controller, psiturk_shell):
import psiturk.experiment_server_controller
from psiturk.psiturk_config import PsiturkConfig
from psiturk.psiturk_shell import PsiturkNetworkShell
import psiturk.psiturk_shell as ps
config = PsiturkConfig()
config.load_config()
config.set('Shell Parameters', 'persistent_history_file', '')
config.set('AWS Access','aws_access_key_id', '')
config.set('AWS Access','aws_secret_access_key', '')
server = psiturk.experiment_server_controller.ExperimentServerController(config)
launch_in_sandbox_mode = True
quiet = False
try:
shell = PsiturkNetworkShell(
config, server,
launch_in_sandbox_mode,
quiet=quiet)
except SystemExit:
pass
out, err = capfd.readouterr()
assert NoMturkConnectionError().message in out
def test_awscreds_notset(capfd, experiment_server_controller, psiturk_shell):
from psiturk.psiturk_config import PsiturkConfig
from psiturk.psiturk_shell import PsiturkNetworkShell
import psiturk.psiturk_shell as ps
import psiturk.experiment_server_controller
config = PsiturkConfig()
config.load_config()
config.set('Shell Parameters', 'persistent_history_file', '')
config.set('AWS Access','aws_access_key_id', 'YourAccessKeyId')
config.set('AWS Access','aws_secret_access_key', 'YourSecretAccessKey')
server = psiturk.experiment_server_controller.ExperimentServerController(config)
launch_in_sandbox_mode = True
quiet = False
try:
shell = PsiturkNetworkShell(
config, server,
launch_in_sandbox_mode,
quiet=quiet)
except SystemExit:
pass
out, err = capfd.readouterr()
assert AWSAccessKeysNotSetError().message in out
os.chdir('..')
shutil.rmtree('psiturk-example', ignore_errors=True)
do_setup()
import psiturk.experiment_server_controller as control
from psiturk.psiturk_config import PsiturkConfig
from psiturk.psiturk_shell import PsiturkNetworkShell
try:
config = PsiturkConfig()
config.load_config()
server = control.ExperimentServerController(config)
launch_in_sandbox_mode = True
quiet = False
shell = PsiturkNetworkShell(
config, server,
launch_in_sandbox_mode,
quiet=quiet)
shell.persistent_history_file = None
# #########################
# all `do_` commands:
# #################
# [] def do_psiturk_status
# [] def do_debug
def experiment_server_controller(mocker):
import psiturk.experiment_server_controller
mocker.patch.object(psiturk.experiment_server_controller.ExperimentServerController, 'is_port_available', lambda *args, **kwargs: True)
using_libedit = 'libedit' in readline.__doc__
if using_libedit:
self.poutput(colorize('\n'.join([
'libedit version of readline detected.',
'readline will not be well behaved, which may cause all sorts',
'of problems for the psiTurk shell. We highly recommend installing',
'the gnu version of readline by running "sudo pip install gnureadline".',
'Note: "pip install readline" will NOT work because of how the OSX',
'pythonpath is structured.'
]), 'red', False))
# Drop arguments which were already processed in command_line.py
sys.argv = [sys.argv[0]]
#opt = docopt(__doc__, sys.argv[1:])
config = PsiturkConfig()
config.load_config()
server = control.ExperimentServerController(config)
shell = PsiturkNetworkShell(
config, server,
config.getboolean('Shell Parameters', 'launch_in_sandbox_mode'),
quiet=quiet)
if script:
shell.runcmds_plus_hooks(['load {}'.format(script)])
elif execute:
shell.runcmds_plus_hooks([execute])
elif testfile:
shell.run_transcript_tests(testfile)
else:
shell.cmdloop()