Ejemplo n.º 1
0
    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'
            ]))
Ejemplo n.º 2
0
    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])})
Ejemplo n.º 3
0
    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]))
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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']))
Ejemplo n.º 6
0
    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')]))
Ejemplo n.º 7
0
    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')]))
Ejemplo n.º 8
0
 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'),
         ])
     )
Ejemplo n.º 9
0
    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'
            ]))
Ejemplo n.º 10
0
    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']))
Ejemplo n.º 11
0
    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'))]))
Ejemplo n.º 12
0
    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'
            ]))
Ejemplo n.º 13
0
    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'
        ]))
Ejemplo n.º 14
0
 def test_depfixer(self):
     self.assertEqual(self.tool('depfile'), shell_list([
         self.tool, shell_literal('<'), 'depfile', shell_literal('>>'),
         'depfile'
     ]))
Ejemplo n.º 15
0
 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'])
Ejemplo n.º 16
0
    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]))
Ejemplo n.º 17
0
 def test_empty(self):
     self.assertEqual(posix.local_env({}, 'cmd'),
                      shell_list([shell_literal('cmd')]))
     self.assertEqual(posix.local_env({}, ['cmd']), ['cmd'])
Ejemplo n.º 18
0
 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'])
Ejemplo n.º 19
0
 def test_path(self):
     self.assertEqual(posix.escape_line(Path('foo')),
                      shell_list([Path('foo')]))
Ejemplo n.º 20
0
    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]))
Ejemplo n.º 21
0
 def test_repr(self):
     x = shell_list([1, 2, 3])
     self.assertEqual(repr(x), '<shell_list([1, 2, 3])>')
Ejemplo n.º 22
0
 def test_jbos(self):
     self.assertEqual(
         windows.escape_line(jbos('foo', literal('bar'))),
         shell_list([jbos(shell_literal('foo'), literal('bar'))]))
Ejemplo n.º 23
0
 def test_string(self):
     self.assertEqual(windows.escape_line('foo bar'),
                      shell_list([shell_literal('foo bar')]))