示例#1
0
class TestFolderOptionNoDefault(unittest.TestCase, OptionTest):
    """Tests FolderOption without a default value."""

    valid_success = [
        '/tmp',
    ]
    valid_failure = [
        '/tmp/1',
    ]

    encode_success = zip(valid_success, valid_success)

    decode_success = zip(valid_success, valid_success)
    decode_failure = valid_failure

    def setUp(self):
        self.option = FolderOption()

    def test_presentation(self):
        path = tempfile.mkdtemp()
        shutil.rmtree(path)

        presentation_value = self.option.presentation(path)
        self.assertEqual(presentation_value, path)
        self.assertFalse(os.path.exists(presentation_value))

    def test_schema(self):
        """Tests StringOption schema method."""
        self.assertRaises(ValidationError, validate, 1, self.option.schema())
        self.assertIsNone(validate('/tmp2', self.option.schema()))
        self.assertDictEqual(self.option.schema(), {'type': 'string'})
示例#2
0
class TestFolderOptionWithDefault(TestFolderOptionNoDefault):
    """Tests FolderOption with a default value."""

    def setUp(self):
        self.option = FolderOption('/tmp')

    def test_default(self):
        """Tests that the default was set correctly."""
        self.assertEqual(self.option.default, '/tmp')

    def test_schema(self):
        """Tests StringOption schema method."""
        self.assertRaises(ValidationError, validate, 1, self.option.schema())
        self.assertIsNone(validate('/tmp2', self.option.schema()))
        self.assertDictEqual(self.option.schema(), {'default': '/tmp', 'type': 'string'})
示例#3
0
class TestFolderOptionNoDefault(unittest.TestCase, OptionTest):
    """Tests FolderOption without a default value."""

    valid_success = [
        '/tmp',
    ]
    valid_failure = [
        '/tmp/1',
    ]

    encode_success = zip(valid_success, valid_success)

    decode_success = zip(valid_success, valid_success)
    decode_failure = valid_failure

    def setUp(self):
        self.option = FolderOption()

    def test_presentation(self):
        path = tempfile.mkdtemp()
        shutil.rmtree(path)

        presentation_value = self.option.presentation(path)
        self.assertEqual(presentation_value, path)
        self.assertFalse(os.path.exists(presentation_value))
示例#4
0
class TestFolderOptionNoDefault(unittest.TestCase, OptionTest):
    """Tests FolderOption without a default value."""

    valid_success = [
        '/tmp',
    ]
    valid_failure = [
        '/tmp/1',
    ]

    encode_success = zip(valid_success, valid_success)

    decode_success = zip(valid_success, valid_success)
    decode_failure = valid_failure

    def setUp(self):
        self.option = FolderOption()

    def test_presentation(self):
        path = tempfile.mkdtemp()
        shutil.rmtree(path)

        presentation_value = self.option.presentation(path)
        self.assertEqual(presentation_value, path)
        self.assertFalse(os.path.exists(presentation_value))
示例#5
0
class TestFolderOptionAutoCreate(TestFolderOptionNoDefault):
    """Tests FolderOption without a default value, and with auto_create turned on."""

    valid_failure = []

    decode_failure = []

    def setUp(self):
        self.option = FolderOption(auto_create=True)

    def test_presentation(self):
        path = tempfile.mkdtemp()
        shutil.rmtree(path)

        presentation_value = self.option.presentation(path)
        self.assertEqual(presentation_value, path)
        self.assertTrue(os.path.exists(presentation_value))

        shutil.rmtree(path)
示例#6
0
class TestFolderOptionAutoCreate(TestFolderOptionNoDefault):
    """Tests FolderOption without a default value, and with auto_create turned on."""

    valid_failure = []

    decode_failure = []

    def setUp(self):
        self.option = FolderOption(auto_create=True)

    def test_presentation(self):
        path = tempfile.mkdtemp()
        shutil.rmtree(path)

        presentation_value = self.option.presentation(path)
        self.assertEqual(presentation_value, path)
        self.assertTrue(os.path.exists(presentation_value))

        shutil.rmtree(path)
示例#7
0
 def setUp(self):
     self.option = FolderOption('/tmp')
示例#8
0
 def setUp(self):
     self.option = FolderOption(auto_create=True)
示例#9
0
 def setUp(self):
     self.option = FolderOption('/tmp')
示例#10
0
 def setUp(self):
     self.option = FolderOption(auto_create=True)