예제 #1
0
class TestPlaceholderCheck(TypeTestCase):
    p = placeholder(1)

    def test_simple(self):
        check = placeholder_check(string, 1)
        self.assertEqual(check('field', 'foo'), 'foo')
        self.assertEqual(check('field', self.p), self.p)
        self.assertEqual(check('field', 'foo' + self.p), 'foo' + self.p)

        with self.assertFieldError(('field', ), 'expected a string'):
            check('field', 1)

    def test_dict(self):
        check = placeholder_check(dict_shape({'foo': string}, 'a foo dict'), 1)
        self.assertEqual(check('field', {'foo': 'bar'}), {'foo': 'bar'})
        self.assertEqual(check('field', {'foo': self.p}), {'foo': self.p})
        self.assertEqual(check('field', {'foo': 'bar' + self.p}),
                         {'foo': 'bar' + self.p})

        with self.assertFieldError(('field', 'bad'), 'unexpected key'):
            check('field', {'bad': self.p})

    def test_invalid_type(self):
        with self.assertFieldError(('field', ), 'expected a boolean'):
            placeholder_check(boolean, 1)('field', self.p)
예제 #2
0
 def test_invalid(self):
     with self.assertFieldError(('field', )):
         string('field', 1)
     with self.assertFieldError(('field', )):
         string('field', None)
     with self.assertFieldError(('field', )):
         string('field', placeholder('foo'))
예제 #3
0
    def test_placeholder_list(self):
        srcdir = Path('srcdir', '')
        srcdir_ph = placeholder(srcdir)

        self.assertShellArgs([srcdir_ph], [srcdir])
        self.assertShellArgs(['foo', srcdir_ph, 'bar'], ['foo', srcdir, 'bar'])
        self.assertShellArgs([srcdir_ph + '/foo'], [(srcdir, '/foo')])
        self.assertShellArgs([srcdir_ph + '/ foo'], [(srcdir, '/ foo')])
예제 #4
0
    def test_ensure_path_placeholder(self):
        srcdir = placeholder(Path(Path.Base.srcdir, ''))
        self.assertEqual(Path.ensure_path(srcdir, Path.Base.srcdir),
                         Path(Path.Base.srcdir, ''))
        self.assertEqual(Path.ensure_path(srcdir + '/foo', Path.Base.srcdir),
                         Path(Path.Base.srcdir, 'foo'))

        subsrc = placeholder(Path(Path.Base.srcdir, 'subdir'))
        self.assertEqual(Path.ensure_path(subsrc, Path.Base.srcdir),
                         Path(Path.Base.srcdir, 'subdir'))
        self.assertEqual(Path.ensure_path(subsrc + '/foo', Path.Base.srcdir),
                         Path(Path.Base.srcdir, 'subdir/foo'))
        self.assertEqual(Path.ensure_path(subsrc + 'foo', Path.Base.srcdir),
                         Path(Path.Base.srcdir, 'subdirfoo'))

        with self.assertRaises(ValueError):
            Path.ensure_path(srcdir + 'foo', Path.Base.srcdir)
        with self.assertRaises(ValueError):
            Path.ensure_path(srcdir + '/foo' + srcdir, Path.Base.srcdir)
예제 #5
0
    def test_placeholder_string(self):
        srcdir = Path('srcdir', '')
        srcdir_ph = placeholder(srcdir)

        self.assertShellArgs(srcdir_ph, [srcdir])
        self.assertShellArgs(srcdir_ph + ' foo', [srcdir, 'foo'])
        self.assertShellArgs('foo ' + srcdir_ph + ' bar',
                             ['foo', srcdir, 'bar'])
        self.assertShellArgs(srcdir_ph + '/foo', [(srcdir, '/foo')])
        self.assertShellArgs('"' + srcdir_ph + '/ foo"', [(srcdir, '/ foo')])
예제 #6
0
class TestPlaceholderFill(TypeTestCase):
    p = placeholder(1)

    def test_foo(self):
        check = placeholder_fill(string, 1, 'one')
        self.assertEqual(check('field', 'foo'), 'foo')
        self.assertEqual(check('field', self.p), 'one')
        self.assertEqual(check('field', 'foo' + self.p), 'fooone')

    def test_dict(self):
        check = placeholder_fill(dict_shape({'foo': string}, 'a foo dict'), 1,
                                 'one')
        self.assertEqual(check('field', {'foo': 'bar'}), {'foo': 'bar'})
        self.assertEqual(check('field', {'foo': self.p}), {'foo': 'one'})
        self.assertEqual(check('field', {'foo': 'bar' + self.p}),
                         {'foo': 'barone'})

        with self.assertFieldError(('field', 'bad'), 'unexpected key'):
            check('field', {'bad': self.p})

    def test_invalid_type(self):
        with self.assertFieldError(('field', ), 'expected a boolean'):
            placeholder_fill(boolean, 1, 'one')('field', self.p)
예제 #7
0
import os
from unittest import TestCase

from mopack.path import Path
from mopack.placeholder import placeholder
from mopack.shell import *

srcdir = Path('srcdir', '')
srcdir_ph = placeholder(srcdir)


class TestSplitWindows(TestCase):
    def assertSplitEqual(self, value, expected, **kwargs):
        self.assertEqual(split_windows_str(value, **kwargs), expected)
        self.assertEqual(split_windows(value, **kwargs),
                         ShellArguments(expected))

    def test_single(self):
        self.assertSplitEqual('foo', ['foo'])
        self.assertSplitEqual(' foo', ['foo'])
        self.assertSplitEqual('foo ', ['foo'])
        self.assertSplitEqual(' foo ', ['foo'])

    def test_multiple(self):
        self.assertSplitEqual('foo bar baz', ['foo', 'bar', 'baz'])

    def test_backslash(self):
        self.assertSplitEqual(r'C:\path\to\file', [r'C:\path\to\file'])

    def test_quote(self):
        self.assertSplitEqual('foo "bar baz"', ['foo', 'bar baz'])
예제 #8
0
 def test_valid(self):
     s = placeholder('foo')
     self.assertEqual(placeholder_string('field', 'foo'), 'foo')
     self.assertEqual(placeholder_string('field', s), s)