Skip to content
This repository has been archived by the owner on May 28, 2022. It is now read-only.

Commit

Permalink
Adds test_float file and moves option schema tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
FranciscoCanas committed Nov 18, 2014
1 parent fa33a7c commit 1f46220
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 36 deletions.
13 changes: 13 additions & 0 deletions src/freeseer/tests/framework/config/options/test_boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# http://wiki.github.com/Freeseer/freeseer/

import unittest
from jsonschema import ValidationError, validate

from freeseer.framework.config.options import BooleanOption
from freeseer.tests.framework.config.options import OptionTest
Expand Down Expand Up @@ -53,6 +54,12 @@ class TestBooleanOptionNoDefault(unittest.TestCase, OptionTest):
def setUp(self):
self.option = BooleanOption()

def test_boolean_schema(self):
"""Tests BooleanOption schema method."""
self.assertRaises(ValidationError, validate, 4, self.option.schema())
self.assertIsNone(validate(True, self.option.schema()))
self.assertDictEqual({'type': 'boolean'}, self.option.schema())


class TestBooleanOptionWithDefault(TestBooleanOptionNoDefault):
"""Test BooleanOption with a default value."""
Expand All @@ -63,3 +70,9 @@ def setUp(self):
def test_default(self):
"""Tests that the default was set correctly."""
self.assertEqual(self.option.default, False)

def test_boolean_schema(self):
"""Tests BooleanOption schema method."""
self.assertRaises(ValidationError, validate, 4, self.option.schema())
self.assertIsNone(validate(True, self.option.schema()))
self.assertDictEqual({'default': False, 'type': 'boolean'}, self.option.schema())
26 changes: 26 additions & 0 deletions src/freeseer/tests/framework/config/options/test_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# http://wiki.github.com/Freeseer/freeseer/

import unittest
from jsonschema import validate, ValidationError

from freeseer.framework.config.options import ChoiceOption
from freeseer.tests.framework.config.options import OptionTest
Expand Down Expand Up @@ -52,6 +53,18 @@ def setUp(self):
'world',
])

def test_option_schema(self):
"""Tests a ChoiceOption schema method."""
expected = {
'enum': [
'hello',
'world',
],
}
self.assertRaises(ValidationError, validate, 'error', self.option.schema())
self.assertIsNone(validate('world', self.option.schema()))
self.assertDictEqual(expected, self.option.schema())


class TestChoiceOptionWithDefault(TestChoiceOptionNoDefault):
"""Tests ChoiceOption with a default value."""
Expand All @@ -65,3 +78,16 @@ def setUp(self):
def test_default(self):
"""Tests that the default was set correctly."""
self.assertEqual(self.option.default, 'hello')

def test_option_schema(self):
"""Tests a ChoiceOption schema method."""
expected = {
'default': 'hello',
'enum': [
'hello',
'world',
],
}
self.assertRaises(ValidationError, validate, 'error', self.option.schema())
self.assertIsNone(validate('world', self.option.schema()))
self.assertDictEqual(expected, self.option.schema())
70 changes: 70 additions & 0 deletions src/freeseer/tests/framework/config/options/test_float.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# freeseer - vga/presentation capture software
#
# Copyright (C) 2011, 2013 Free and Open Source Software Learning Centre
# http://fosslc.org
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# For support, questions, suggestions or any other inquiries, visit:
# http://wiki.github.com/Freeseer/freeseer/

import unittest
from jsonschema import validate, ValidationError

from freeseer.framework.config.options import FloatOption
from freeseer.tests.framework.config.options import OptionTest


class TestFloatOptionNoDefault(unittest.TestCase, OptionTest):
"""Tests FloatOption without a default value."""

valid_success = map(lambda x: x / 10.0, range(-100, 100))

encode_success = zip(valid_success, map(str, valid_success))

decode_success = zip(map(str, valid_success), valid_success)
decode_failure = [
'hello',
'1world',
'test2',
]

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

def test_float_schema(self):
"""Tests FloatOption schema method."""
self.assertRaises(ValidationError, validate, 'error', self.option.schema())
self.assertIsNone(validate(5.0, self.option.schema()))
self.assertDictEqual({'type': 'number'}, self.option.schema())


class TestFloatOptionWithDefault(TestFloatOptionNoDefault):
"""Tests FloatOption with a default value."""

def setUp(self):
self.option = FloatOption(1234.0)

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

def test_float_schema(self):
"""Tests FloatOption schema method."""
self.assertRaises(ValidationError, validate, 'error', self.option.schema())
self.assertIsNone(validate(5.0, self.option.schema()))
self.assertDictEqual({'default': 1234.0, 'type': 'number'}, self.option.schema())
13 changes: 13 additions & 0 deletions src/freeseer/tests/framework/config/options/test_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import shutil
import tempfile
import unittest
from jsonschema import validate, ValidationError

from freeseer.framework.config.options import FolderOption
from freeseer.tests.framework.config.options import OptionTest
Expand Down Expand Up @@ -57,6 +58,12 @@ def test_presentation(self):
self.assertEqual(presentation_value, path)
self.assertFalse(os.path.exists(presentation_value))

def test_string_schema(self):
"""Tests StringOption schema method."""
self.assertRaises(ValidationError, validate, 1, self.option.schema())
self.assertIsNone(validate('/tmp2', self.option.schema()))
self.assertDictEqual({'type': 'string'}, self.option.schema())


class TestFolderOptionAutoCreate(TestFolderOptionNoDefault):
"""Tests FolderOption without a default value, and with auto_create turned on."""
Expand Down Expand Up @@ -88,3 +95,9 @@ def setUp(self):
def test_default(self):
"""Tests that the default was set correctly."""
self.assertEqual(self.option.default, '/tmp')

def test_string_schema(self):
"""Tests StringOption schema method."""
self.assertRaises(ValidationError, validate, 1, self.option.schema())
self.assertIsNone(validate('/tmp2', self.option.schema()))
self.assertDictEqual({'default': '/tmp', 'type': 'string'}, self.option.schema())
13 changes: 13 additions & 0 deletions src/freeseer/tests/framework/config/options/test_integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# http://wiki.github.com/Freeseer/freeseer/

import unittest
from jsonschema import validate, ValidationError

from freeseer.framework.config.options import IntegerOption
from freeseer.tests.framework.config.options import OptionTest
Expand All @@ -45,6 +46,12 @@ class TestIntegerOptionNoDefault(unittest.TestCase, OptionTest):
def setUp(self):
self.option = IntegerOption()

def test_integer_schema(self):
"""Tests IntegerOption schema method."""
self.assertRaises(ValidationError, validate, 1.0, self.option.schema())
self.assertIsNone(validate(5, self.option.schema()))
self.assertDictEqual({'type': 'integer'}, self.option.schema())


class TestIntegerOptionWithDefault(TestIntegerOptionNoDefault):
"""Tests IntegerOption with a default value."""
Expand All @@ -55,3 +62,9 @@ def setUp(self):
def test_default(self):
"""Tests that the default was set correctly."""
self.assertEqual(self.option.default, 1234)

def test_integer_schema(self):
"""Tests IntegerOption schema method."""
self.assertRaises(ValidationError, validate, 1.0, self.option.schema())
self.assertIsNone(validate(5, self.option.schema()))
self.assertDictEqual({'default': 1234, 'type': 'integer'}, self.option.schema())
13 changes: 13 additions & 0 deletions src/freeseer/tests/framework/config/options/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# http://wiki.github.com/Freeseer/freeseer/

import unittest
from jsonschema import ValidationError, validate

from freeseer.framework.config.options import StringOption
from freeseer.tests.framework.config.options import OptionTest
Expand Down Expand Up @@ -50,6 +51,12 @@ class TestStringOptionNoDefault(unittest.TestCase, OptionTest):
def setUp(self):
self.option = StringOption()

def test_string_schema(self):
"""Tests StringOption schema method."""
self.assertRaises(ValidationError, validate, 1, self.option.schema())
self.assertIsNone(validate('string_value', self.option.schema()))
self.assertDictEqual({'type': 'string'}, self.option.schema())


class TestStringOptionWithDefault(TestStringOptionNoDefault):
"""Tests StringOption with a default value."""
Expand All @@ -60,3 +67,9 @@ def setUp(self):
def test_default(self):
"""Tests that the default was set correctly."""
self.assertEqual(self.option.default, 'testing')

def test_string_schema(self):
"""Tests StringOption schema method."""
self.assertRaises(ValidationError, validate, 1, self.option.schema())
self.assertIsNone(validate('string_value', self.option.schema()))
self.assertDictEqual({'default': 'testing', 'type': 'string'}, self.option.schema())
36 changes: 0 additions & 36 deletions src/freeseer/tests/framework/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import tempfile
import unittest
from jsonschema import validate, ValidationError
from freeseer.framework.config import options
from freeseer.framework.config.profile import ProfileManager
from freeseer import settings

Expand Down Expand Up @@ -139,38 +138,3 @@ def test_schema_invalidate(self):
'auto_hide': 5
}
self.assertRaises(ValidationError, validate, config, self.config.schema())

def test_option_schema(self):
"""Tests a ChoiceOption schema method."""
new_option = options.ChoiceOption(['A', 'B', 'C'], 'B')
self.assertRaises(ValidationError, validate, 'E', new_option.schema())
self.assertIsNone(validate('A', new_option.schema()))
self.assertDictEqual({'default': 'B', 'enum': ['A', 'B', 'C']}, new_option.schema())

def test_string_schema(self):
"""Tests StringOption schema method."""
new_option = options.StringOption('testing')
self.assertRaises(ValidationError, validate, 1, new_option.schema())
self.assertIsNone(validate('string_value', new_option.schema()))
self.assertDictEqual({'default': 'testing', 'type': 'string'}, new_option.schema())

def test_boolean_schema(self):
"""Tests BooleanOption schema method."""
new_option = options.BooleanOption(True)
self.assertRaises(ValidationError, validate, 4, new_option.schema())
self.assertIsNone(validate(True, new_option.schema()))
self.assertDictEqual({'default': True, 'type': 'boolean'}, new_option.schema())

def test_integer_schema(self):
"""Tests IntegerOption schema method."""
new_option = options.IntegerOption(1)
self.assertRaises(ValidationError, validate, 1.0, new_option.schema())
self.assertIsNone(validate(5, new_option.schema()))
self.assertDictEqual({'default': 1, 'type': 'integer'}, new_option.schema())

def test_float_schema(self):
"""Tests FloatOption schema method."""
new_option = options.FloatOption(0.5)
self.assertRaises(ValidationError, validate, 'string_value', new_option.schema())
self.assertIsNone(validate(3.0, new_option.schema()))
self.assertDictEqual({'default': 0.5, 'type': 'number'}, new_option.schema())

0 comments on commit 1f46220

Please sign in to comment.