def test_multiple(self): env = OrderedDict((('FOO', 'oof'), ('BAR', 'rab'))) self.assertEqual( posix.global_env(env), shell_list([ 'export', jbos('FOO', shell_literal('='), 'oof'), shell_literal('&&'), 'export', jbos('BAR', shell_literal('='), 'rab') ])) self.assertEqual( posix.global_env(env, ['cmd']), shell_list([ 'export', jbos('FOO', shell_literal('='), 'oof'), shell_literal('&&'), 'export', jbos('BAR', shell_literal('='), 'rab'), shell_literal('&&'), shell_literal('cmd') ])) self.assertEqual( posix.global_env(env, [['cmd']]), shell_list([ 'export', jbos('FOO', shell_literal('='), 'oof'), shell_literal('&&'), 'export', jbos('BAR', shell_literal('='), 'rab'), shell_literal('&&'), 'cmd' ]))
def test_merge_lists(self): d = {'foo': [1]} iterutils.merge_into_dict(d, {'foo': [2]}) self.assertEqual(d, {'foo': [1, 2]}) d = {'foo': shell_list([1])} iterutils.merge_into_dict(d, {'foo': shell_list([2])}) self.assertEqual(d, {'foo': shell_list([1, 2])})
def test_append(self): x = shell_list([1, 2, 3]) x += [4, 5] self.assertEqual(x, shell_list([1, 2, 3, 4, 5])) x = [4, 5] x += shell_list([1, 2, 3]) self.assertEqual(x, shell_list([4, 5, 1, 2, 3]))
def test_equals(self): x = shell_list([1, 2, 3]) self.assertTrue(x == shell_list([1, 2, 3])) self.assertTrue(x != shell_list([1, 2, 3, 4])) self.assertTrue(x != [1, 2, 3]) self.assertTrue(x != [1, 2, 3, 4]) self.assertTrue([1, 2, 3] != x) self.assertTrue([1, 2, 3, 4] != x)
def test_single(self): env = {'NAME': 'VALUE'} self.assertEqual( posix.local_env(env, 'cmd'), shell_list([ jbos('NAME', shell_literal('='), 'VALUE'), shell_literal('cmd') ])) self.assertEqual( posix.local_env(env, ['cmd']), shell_list([jbos('NAME', shell_literal('='), 'VALUE'), 'cmd']))
def test_string(self): self.assertEqual(posix.escape_line('foobar'), shell_list([shell_literal(r'foobar')])) with mock.patch('bfg9000.shell.posix.platform_info', return_value=self.FakePlatform('posix')): self.assertEqual(posix.escape_line(r'foo\bar'), shell_list([shell_literal(r'foo\bar')])) with mock.patch('bfg9000.shell.posix.platform_info', return_value=self.FakePlatform('windows')): self.assertEqual(posix.escape_line(r'foo\bar'), shell_list([shell_literal(r'foo\\bar')]))
def test_string(self): class FakePlatform(object): def __init__(self, family): self.family = family with mock.patch('bfg9000.shell.posix.platform_info', return_value=FakePlatform('posix')): self.assertEqual(posix.escape_line(r'foo\bar'), shell_list([shell_literal(r'foo\bar')])) with mock.patch('bfg9000.shell.posix.platform_info', return_value=FakePlatform('windows')): self.assertEqual(posix.escape_line(r'foo\bar'), shell_list([shell_literal(r'foo\\bar')]))
def test_multiple(self): self.assertEqual(windows.join_lines(['foo', 'bar']), shell_list([ shell_literal('foo'), shell_literal('&&'), shell_literal('bar'), ])) self.assertEqual( windows.join_lines([['foo', 'bar'], 'baz']), shell_list([ 'foo', 'bar', shell_literal('&&'), shell_literal('baz'), ]) )
def test_multiple(self): env = OrderedDict((('FOO', 'oof'), ('BAR', 'rab'))) self.assertEqual( posix.local_env(env, 'cmd'), shell_list([ jbos('FOO', shell_literal('='), 'oof'), jbos('BAR', shell_literal('='), 'rab'), shell_literal('cmd') ])) self.assertEqual( posix.local_env(env, ['cmd']), shell_list([ jbos('FOO', shell_literal('='), 'oof'), jbos('BAR', shell_literal('='), 'rab'), 'cmd' ]))
def test_single(self): env = {'NAME': 'VALUE'} self.assertEqual(windows.global_env(env), shell_list(['set', 'NAME=VALUE'])) self.assertEqual( windows.global_env(env, ['cmd']), shell_list([ 'set', 'NAME=VALUE', shell_literal('&&'), shell_literal('cmd') ])) self.assertEqual( windows.global_env(env, [['cmd']]), shell_list(['set', 'NAME=VALUE', shell_literal('&&'), 'cmd']))
def test_jbos(self): self.assertEqual( posix.escape_line(jbos('foo', literal('bar'))), shell_list([jbos(shell_literal('foo'), literal('bar'))])) s = jbos(r'foo\bar', literal(r'baz\quux')) with mock.patch('bfg9000.shell.posix.platform_info', return_value=self.FakePlatform('posix')): self.assertEqual( posix.escape_line(s), shell_list( [jbos(shell_literal(r'foo\bar'), literal(r'baz\quux'))])) with mock.patch('bfg9000.shell.posix.platform_info', return_value=self.FakePlatform('windows')): self.assertEqual( posix.escape_line(s), shell_list( [jbos(shell_literal(r'foo\\bar'), literal(r'baz\quux'))]))
def test_single(self): env = {'NAME': 'VALUE'} self.assertEqual( posix.global_env(env), shell_list(['export', jbos('NAME', shell_literal('='), 'VALUE')])) self.assertEqual( posix.global_env(env, ['cmd']), shell_list([ 'export', jbos('NAME', shell_literal('='), 'VALUE'), shell_literal('&&'), shell_literal('cmd') ])) self.assertEqual( posix.global_env(env, [['cmd']]), shell_list([ 'export', jbos('NAME', shell_literal('='), 'VALUE'), shell_literal('&&'), 'cmd' ]))
def test_multiple(self): env = OrderedDict((('FOO', 'oof'), ('BAR', 'rab'))) self.assertEqual(windows.global_env(env), shell_list([ 'set', 'FOO=oof', shell_literal('&&'), 'set', 'BAR=rab' ])) self.assertEqual(windows.global_env(env, ['cmd']), shell_list([ 'set', 'FOO=oof', shell_literal('&&'), 'set', 'BAR=rab', shell_literal('&&'), shell_literal('cmd') ])) self.assertEqual(windows.global_env(env, [['cmd']]), shell_list([ 'set', 'FOO=oof', shell_literal('&&'), 'set', 'BAR=rab', shell_literal('&&'), 'cmd' ]))
def test_depfixer(self): self.assertEqual(self.tool('depfile'), shell_list([ self.tool, shell_literal('<'), 'depfile', shell_literal('>>'), 'depfile' ]))
def test_empty(self): self.assertEqual(posix.global_env({}), []) self.assertEqual(posix.global_env({}, ['cmd']), shell_list([shell_literal('cmd')])) self.assertEqual(posix.global_env({}, [['cmd']]), ['cmd'])
def test_concat(self): x = shell_list([1, 2, 3]) y = [4, 5] self.assertEqual(x + y, shell_list([1, 2, 3, 4, 5])) self.assertEqual(y + x, shell_list([4, 5, 1, 2, 3]))
def test_empty(self): self.assertEqual(posix.local_env({}, 'cmd'), shell_list([shell_literal('cmd')])) self.assertEqual(posix.local_env({}, ['cmd']), ['cmd'])
def test_single(self): self.assertEqual(posix.join_lines(['foo']), shell_list([shell_literal('foo')])) self.assertEqual(posix.join_lines([['foo']]), ['foo']) self.assertEqual(posix.join_lines([['foo', 'bar']]), ['foo', 'bar'])
def test_path(self): self.assertEqual(posix.escape_line(Path('foo')), shell_list([Path('foo')]))
def test_slice(self): x = shell_list([1, 2, 3]) self.assertEqual(x[:], shell_list([1, 2, 3])) self.assertEqual(x[0:2], shell_list([1, 2])) self.assertEqual(x[0:3:2], shell_list([1, 3]))
def test_repr(self): x = shell_list([1, 2, 3]) self.assertEqual(repr(x), '<shell_list([1, 2, 3])>')
def test_jbos(self): self.assertEqual( windows.escape_line(jbos('foo', literal('bar'))), shell_list([jbos(shell_literal('foo'), literal('bar'))]))
def test_string(self): self.assertEqual(windows.escape_line('foo bar'), shell_list([shell_literal('foo bar')]))