def test_expand_file_prefixed_files(self): f = tempfile.NamedTemporaryFile(delete=False) f.close() f_with_bom = tempfile.NamedTemporaryFile(delete=False) f_with_bom.close() with open(f.name, 'w+') as stream: stream.write('foo') from codecs import open as codecs_open with codecs_open(f_with_bom.name, encoding='utf-8-sig', mode='w+') as stream: stream.write('foo') cases = [ [['bar=baz'], ['bar=baz']], [['bar', 'baz'], ['bar', 'baz']], [['bar=@{}'.format(f.name)], ['bar=foo']], [['bar=@{}'.format(f_with_bom.name)], ['bar=foo']], [['bar', '@{}'.format(f.name)], ['bar', 'foo']], [['bar', f.name], ['bar', f.name]], [['[email protected]'], ['[email protected]']], [['bar', '*****@*****.**'], ['bar', '*****@*****.**']], [['bar=mymongo=@connectionstring'], ['bar=mymongo=@connectionstring']] ] for test_case in cases: try: args = Application._expand_file_prefixed_files(test_case[0]) # pylint: disable=protected-access self.assertEqual(args, test_case[1], 'Failed for: {}'.format(test_case[0])) except CLIError as ex: self.fail('Unexpected error for {} ({}): {}'.format(test_case[0], args, ex)) os.remove(f.name)
def test_expand_file_prefixed_files(self): f = tempfile.NamedTemporaryFile(delete=False) f.close() f_with_bom = tempfile.NamedTemporaryFile(delete=False) f_with_bom.close() with open(f.name, 'w+') as stream: stream.write('foo') from codecs import open as codecs_open with codecs_open(f_with_bom.name, encoding='utf-8-sig', mode='w+') as stream: stream.write('foo') cases = [[['bar=baz'], ['bar=baz']], [['bar', 'baz'], ['bar', 'baz']], [['bar=@{}'.format(f.name)], ['bar=foo']], [['bar=@{}'.format(f_with_bom.name)], ['bar=foo']], [['bar', '@{}'.format(f.name)], ['bar', 'foo']], [['bar', f.name], ['bar', f.name]], [['[email protected]'], ['[email protected]']], [['bar', '*****@*****.**'], ['bar', '*****@*****.**']], [['bar=mymongo=@connectionstring'], ['bar=mymongo=@connectionstring']]] for test_case in cases: try: args = Application._expand_file_prefixed_files(test_case[0]) # pylint: disable=protected-access self.assertEqual(args, test_case[1], 'Failed for: {}'.format(test_case[0])) except CLIError as ex: self.fail('Unexpected error for {} ({}): {}'.format( test_case[0], args, ex)) os.remove(f.name)
def test_expand_file_prefixed_files(self): f = tempfile.NamedTemporaryFile(delete=False) f.close() with open(f.name, 'w+') as stream: stream.write('foo') cases = [ [['--bar=baz'], ['--bar=baz']], [['--bar', 'baz'], ['--bar', 'baz']], [['--bar=@{}'.format(f.name)], ['--bar=foo']], [['--bar', '@{}'.format(f.name)], ['--bar', 'foo']], [['--bar', f.name], ['--bar', f.name]], [['--bar="@{}"'.format(f.name)], ['--bar=foo']], [['[email protected]'], ['[email protected]']], [['--bar', '*****@*****.**'], ['--bar', '*****@*****.**']], ] for test_case in cases: try: args = Application._expand_file_prefixed_files(test_case[0]) #pylint: disable=protected-access self.assertEqual(args, test_case[1], 'Failed for: {}'.format(test_case[0])) except CLIError as ex: self.fail('Unexpected error for {} ({}): {}'.format( test_case[0], args, ex)) os.remove(f.name)