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'])
def test_index_twice(self): p = Placeholder('files') self.assertRaises(TypeError, lambda: p[0][0]) self.assertRaises(TypeError, lambda: p[0:1][0]) self.assertRaises(TypeError, lambda: p[0][0:1]) self.assertRaises(TypeError, lambda: p[0:1][0:1])
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)
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'])
def test_expand_slice(self): p = Placeholder('files')[0:1] self.assertEqual(p.expand(AttrDict(files=[])), []) self.assertEqual(p.expand(AttrDict(files=['foo'])), ['foo']) self.assertEqual(p.expand(AttrDict(files=['foo', 'bar'])), ['foo'])
def test_expand_index(self): p = Placeholder('files')[0] with self.assertRaises(IndexError): p.expand(AttrDict(files=[])) self.assertEqual(p.expand(AttrDict(files=['foo'])), ['foo']) self.assertEqual(p.expand(AttrDict(files=['foo', 'bar'])), ['foo'])