Beispiel #1
0
 def test_expand_word_misc(self):
     self.assertEqual(Placeholder.expand_word('foo', AttrDict(files=[])),
                      ['foo'])
     self.assertEqual(
         Placeholder.expand_word('foo', AttrDict(files=['foo'])), ['foo'])
     self.assertEqual(
         Placeholder.expand_word('foo', AttrDict(files=['foo', 'bar'])),
         ['foo'])
Beispiel #2
0
    def test_expand_word(self):
        p = Placeholder('files')
        zero = AttrDict(files=[])
        one = AttrDict(files=['foo'])
        two = AttrDict(files=['foo', 'bar'])

        self.assertEqual(Placeholder.expand_word(p, zero), [])
        self.assertEqual(Placeholder.expand_word(p, one), ['foo'])
        self.assertEqual(Placeholder.expand_word(p, two), ['foo', 'bar'])

        with self.assertRaises(IndexError):
            Placeholder.expand_word(p[0], zero)
        self.assertEqual(Placeholder.expand_word(p[0], one), ['foo'])
        self.assertEqual(Placeholder.expand_word(p[0], two), ['foo'])

        self.assertEqual(Placeholder.expand_word(p[0:1], zero), [])
        self.assertEqual(Placeholder.expand_word(p[0:1], one), ['foo'])
        self.assertEqual(Placeholder.expand_word(p[0:1], two), ['foo'])
Beispiel #3
0
    def test_expand_word_jbos(self):
        p = Placeholder('files')
        zero = AttrDict(files=[])
        one = AttrDict(files=[literal('foo')])
        two = AttrDict(files=[literal('foo'), literal('bar')])
        foo = jbos('{', literal('foo'), '}')
        bar = jbos('{', literal('bar'), '}')

        j = '{' + p + '}'
        self.assertEqual(Placeholder.expand_word(j, zero), [])
        self.assertEqual(Placeholder.expand_word(j, one), [foo])
        self.assertEqual(Placeholder.expand_word(j, two), [foo, bar])

        j = '{' + p[0] + '}'
        with self.assertRaises(IndexError):
            Placeholder.expand_word(j, zero)
        self.assertEqual(Placeholder.expand_word(j, one), [foo])
        self.assertEqual(Placeholder.expand_word(j, two), [foo])

        j = '{' + p[0:1] + '}'
        self.assertEqual(Placeholder.expand_word(j, zero), [])
        self.assertEqual(Placeholder.expand_word(j, one), [foo])
        self.assertEqual(Placeholder.expand_word(j, two), [foo])

        j = jbos('foo')
        self.assertEqual(Placeholder.expand_word(j, zero), [j])
        self.assertEqual(Placeholder.expand_word(j, one), [j])
        self.assertEqual(Placeholder.expand_word(j, two), [j])

        with self.assertRaises(ValueError):
            Placeholder.expand_word(p + p, zero)