def test_token_without_username(): parser = make_connection_parser() some_token = 'some_token' args = parser.parse_args(['--token', some_token]) user = get_user(args) assert user.token == some_token assert user.host == DEFAULT_HOST
def test_parse_user_by_email(): user = get_user(make_connection_parser().parse_args( ['-u', '*****@*****.**'])) expected = User('*****@*****.**', alias='*****@*****.**', host='platform.genestack.org') assert user == expected
def generate_rst_doc(shell_name, file_name, class_name, footer_file_name, save_path): with open(os.path.join(os.path.dirname(__file__), '..', '..', 'genestack_client', 'scripts', file_name)) as f: shell_module = imp.new_module('shell_name') exec(f.read(), shell_module.__dict__) shell = getattr(shell_module, class_name) tool_file_name = os.path.basename(shell_name) commands = [] script_help = get_help(shell().get_shell_parser()).replace("\n", "\n ").replace('sphinx-build', tool_file_name) for command in sorted(shell.COMMAND_LIST, key=lambda x: x.COMMAND): command = command() parser = command.get_command_parser(parser=None if command.OFFLINE else make_connection_parser()) help_text = get_help(parser).replace("\n", "\n ").replace('sphinx-build', tool_file_name) text = '- **%s**:\n\n .. code-block:: text\n\n %s\n\n' % (command.COMMAND, help_text) commands.append(text) if footer_file_name: with open(footer_file_name) as f: footer = f.read() else: footer = '' with open(save_path, 'w') as f: f.write(template.format( name=tool_file_name, name_underline='=' * len(tool_file_name), commands='\n'.join(commands), description=shell.DESCRIPTION, usage=script_help, footer=footer, ))
def args(): p = make_connection_parser() p.add_argument( '--keep', action='store_true', help='Keep created test files for manual inspection or initialization') return p.parse_args()
def test_parse_default_user(): user = get_user(make_connection_parser().parse_args()) expected = User('*****@*****.**', alias='tester', host='localhost:8080', password='******', token=None) assert user == expected
def test_parse_default(): parser = make_connection_parser() args = parser.parse_args() expected = Namespace(debug=False, host=None, pwd=None, show_logs=False, user=None, token=None) assert args == expected
def generate_rst_doc(shell_name, file_name, class_name, footer_file_name, save_path): with open( os.path.join(os.path.dirname(__file__), '..', '..', 'genestack_client', 'scripts', file_name)) as f: shell_module = imp.new_module('shell_name') exec(f.read(), shell_module.__dict__) shell = getattr(shell_module, class_name) tool_file_name = os.path.basename(shell_name) commands = [] script_help = get_help(shell().get_shell_parser()).replace( "\n", "\n ").replace('sphinx-build', tool_file_name) for command in sorted(shell.COMMAND_LIST, key=lambda x: x.COMMAND): command = command() parser = command.get_command_parser( parser=None if command.OFFLINE else make_connection_parser()) help_text = get_help(parser).replace("\n", "\n ").replace( 'sphinx-build', tool_file_name) text = '- **%s**:\n\n .. code-block:: text\n\n %s\n\n' % ( command.COMMAND, help_text) commands.append(text) if footer_file_name: with open(footer_file_name) as f: footer = f.read() else: footer = '' with open(save_path, 'w') as f: f.write( template.format( name=tool_file_name, name_underline='=' * len(tool_file_name), commands='\n'.join(commands), description=shell.DESCRIPTION, usage=script_help, footer=footer, ))
def test_token_and_user(capsys): parser = make_connection_parser() with pytest.raises(SystemExit): parser.parse_args(['-u', 'some_user', '--token', 'some_token']) # Test stderr output that was written by parser before raising error: # Expected output consist of usage section and line with filename and tested error expected_error_message = 'Token and user should not be specified together' # Save parser.print_usage output to the variable f = StringIO() parser.print_usage(file=f) expected_output = f.getvalue() expected_output += '%s: error: %s\n' % (os.path.basename(__file__), expected_error_message) # capture stdout and stderr that was produced during test # https://docs.pytest.org/en/latest/capture.html#accessing-captured-output-from-a-test-function out, err = capsys.readouterr() assert err == expected_output
def test_token_and_user(capsys): parser = make_connection_parser() with pytest.raises(SystemExit): parser.parse_args(['-u', 'some_user', '--token', 'some_token']) # Test stderr output that was written by parser before raising error: # Expected output consist of usage section and line with filename and tested error expected_error_message = 'Token and user should not be specified together' # Save parser.print_usage output to the variable f = StringIO() parser.print_usage(file=f) expected_output = f.getvalue() expected_output += '%s: error: %s\n' % ( os.path.basename(__file__), expected_error_message) # capture stdout and stderr that was produced during test # https://docs.pytest.org/en/latest/capture.html#accessing-captured-output-from-a-test-function out, err = capsys.readouterr() assert err == expected_output
GenestackException) # keys that must be supplied in the CSV file MANDATORY_KEYS = ['name', 'link'] # keys that have existing dedicated "Genestack" metainfo key names SPECIAL_KEYS = { 'name': BioMetainfo.NAME, 'organism': BioMetainfo.ORGANISM, 'method': BioMetainfo.METHOD, 'sex': BioMetainfo.SEX, 'cell line': BioMetainfo.CELL_LINE } # parse script arguments parser = make_connection_parser() parser.add_argument( 'csv_file', help='Path to the local comma-delimited CSV file containing the data') parser.add_argument('--name', help='Name of the experiment to create in Genestack') parser.add_argument( '--description', help='Description of the experiment to display in Genestack') args = parser.parse_args() csv_input = args.csv_file print "Connecting to Genestack..." # get connection and application handlers
# Logic to parse 'boolean-like' values as metainfo booleans TRUE_VALUES = {'true', 'yes', 'y'} FALSE_VALUES = {'false', 'no', 'n'} def parse_as_boolean(s): if s.lower().strip() in TRUE_VALUES: return True elif s.lower().strip() in FALSE_VALUES: return False return None if __name__ == "__main__": # parse script arguments parser = make_connection_parser() parser.add_argument('csv_file', help='Path to the local comma-delimited CSV file containing the data') parser.add_argument('local_key', help='Name of the local key to match CSV records and Genestack files names') parser.add_argument('folder', help='Accession of the Genestack folder containing the files') args = parser.parse_args() csv_input = args.csv_file local_key = args.local_key print "Connecting to Genestack..." # get connection and application handlers connection = get_connection(args) files_util = FilesUtil(connection) print "Collecting files..."
def files_utils(): connection = get_connection(make_connection_parser().parse_args([])) files_utils = FilesUtil(connection) return files_utils
def conn(): conn = get_connection(make_connection_parser().parse_args()) return conn
def args(): p = make_connection_parser() p.add_argument('--keep', action='store_true', help='Keep created test files for manual inspection or initialization') return p.parse_args()
def test_parse_user_by_email(): user = get_user(make_connection_parser().parse_args(['-u', '*****@*****.**'])) expected = User('*****@*****.**', alias='*****@*****.**', host='platform.genestack.org') assert user == expected