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

Commit

Permalink
Updates for formatting, doc, and style feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
FranciscoCanas committed Nov 19, 2014
1 parent 8feed84 commit 08784e5
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 50 deletions.
4 changes: 2 additions & 2 deletions src/freeseer/framework/config/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# freeseer - vga/presentation capture software
#
# Copyright (C) 2011, 2013 Free and Open Source Software Learning Centre
# Copyright (C) 2011, 2013, 2014 Free and Open Source Software Learning Centre
# http://fosslc.org
#
# This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -58,7 +58,7 @@ def presentation(self, value):

def schema(self):
"""Returns the json schema for an Option."""
schema = {'type': self.schema_type}
schema = {'type': self.SCHEMA_TYPE}
if self.default != self.NotSpecified:
schema['default'] = self.default
return schema
Expand Down
14 changes: 7 additions & 7 deletions src/freeseer/framework/config/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# freeseer - vga/presentation capture software
#
# Copyright (C) 2011, 2013 Free and Open Source Software Learning Centre
# Copyright (C) 2011, 2013, 2014 Free and Open Source Software Learning Centre
# http://fosslc.org
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -30,7 +30,7 @@

class StringOption(Option):
"""Represents a string value."""
schema_type = 'string'
SCHEMA_TYPE = 'string'

def is_valid(self, value):
return isinstance(value, str) or hasattr(value, '__str__')
Expand All @@ -44,7 +44,7 @@ def decode(self, value):

class IntegerOption(Option):
"""Represents an integer number value."""
schema_type = 'integer'
SCHEMA_TYPE = 'integer'

def is_valid(self, value):
return isinstance(value, int)
Expand All @@ -61,7 +61,7 @@ def decode(self, value):

class FloatOption(Option):
"""Represents a floating point number value."""
schema_type = 'number'
SCHEMA_TYPE = 'number'

def is_valid(self, value):
return isinstance(value, float)
Expand All @@ -78,7 +78,7 @@ def decode(self, value):

class BooleanOption(Option):
"""Represents a boolean value."""
schema_type = 'boolean'
SCHEMA_TYPE = 'boolean'

def is_valid(self, value):
return isinstance(value, bool)
Expand All @@ -92,7 +92,7 @@ def decode(self, value):

class FolderOption(Option):
"""Represents the path to a folder."""
schema_type = 'string'
SCHEMA_TYPE = 'string'

def __init__(self, default=Option.NotSpecified, auto_create=False):
self.auto_create = auto_create
Expand Down Expand Up @@ -124,7 +124,7 @@ def presentation(self, value):

class ChoiceOption(StringOption):
"""Represents a selection from a pre-defined list of strings."""
schema_type = 'enum'
SCHEMA_TYPE = 'enum'

def __init__(self, choices, default=Option.NotSpecified):
self.choices = choices
Expand Down
13 changes: 7 additions & 6 deletions src/freeseer/tests/framework/config/options/test_boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# freeseer - vga/presentation capture software
#
# Copyright (C) 2011, 2013 Free and Open Source Software Learning Centre
# Copyright (C) 2011, 2013, 2014 Free and Open Source Software Learning Centre
# http://fosslc.org
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -24,7 +24,8 @@

import unittest

from jsonschema import ValidationError, validate
from jsonschema import validate
from jsonschema import ValidationError

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

def test_boolean_schema(self):
def test_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())
self.assertDictEqual(self.option.schema(), {'type': 'boolean'})


class TestBooleanOptionWithDefault(TestBooleanOptionNoDefault):
Expand All @@ -72,8 +73,8 @@ def test_default(self):
"""Tests that the default was set correctly."""
self.assertEqual(self.option.default, False)

def test_boolean_schema(self):
def test_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())
self.assertDictEqual(self.option.schema(), {'default': False, 'type': 'boolean'})
13 changes: 7 additions & 6 deletions src/freeseer/tests/framework/config/options/test_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# freeseer - vga/presentation capture software
#
# Copyright (C) 2011, 2013 Free and Open Source Software Learning Centre
# Copyright (C) 2011, 2013, 2014 Free and Open Source Software Learning Centre
# http://fosslc.org
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -24,7 +24,8 @@

import unittest

from jsonschema import validate, ValidationError
from jsonschema import validate
from jsonschema import ValidationError

from freeseer.framework.config.options import ChoiceOption
from freeseer.tests.framework.config.options import OptionTest
Expand Down Expand Up @@ -54,7 +55,7 @@ def setUp(self):
'world',
])

def test_option_schema(self):
def test_schema(self):
"""Tests a ChoiceOption schema method."""
expected = {
'enum': [
Expand All @@ -64,7 +65,7 @@ def test_option_schema(self):
}
self.assertRaises(ValidationError, validate, 'error', self.option.schema())
self.assertIsNone(validate('world', self.option.schema()))
self.assertDictEqual(expected, self.option.schema())
self.assertDictEqual(self.option.schema(), expected)


class TestChoiceOptionWithDefault(TestChoiceOptionNoDefault):
Expand All @@ -80,7 +81,7 @@ def test_default(self):
"""Tests that the default was set correctly."""
self.assertEqual(self.option.default, 'hello')

def test_option_schema(self):
def test_schema(self):
"""Tests a ChoiceOption schema method."""
expected = {
'default': 'hello',
Expand All @@ -91,4 +92,4 @@ def test_option_schema(self):
}
self.assertRaises(ValidationError, validate, 'error', self.option.schema())
self.assertIsNone(validate('world', self.option.schema()))
self.assertDictEqual(expected, self.option.schema())
self.assertDictEqual(self.option.schema(), expected)
15 changes: 8 additions & 7 deletions src/freeseer/tests/framework/config/options/test_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# freeseer - vga/presentation capture software
#
# Copyright (C) 2011, 2013 Free and Open Source Software Learning Centre
# Copyright (C) 2014 Free and Open Source Software Learning Centre
# http://fosslc.org
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -24,7 +24,8 @@

import unittest

from jsonschema import validate, ValidationError
from jsonschema import validate
from jsonschema import ValidationError

from freeseer.framework.config.options import FloatOption
from freeseer.tests.framework.config.options import OptionTest
Expand All @@ -33,7 +34,7 @@
class TestFloatOptionNoDefault(unittest.TestCase, OptionTest):
"""Tests FloatOption without a default value."""

valid_success = map(lambda x: x / 10.0, range(-100, 100))
valid_success = [x / 10.0 for x in xrange(-100, 100)]

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

Expand All @@ -47,11 +48,11 @@ class TestFloatOptionNoDefault(unittest.TestCase, OptionTest):
def setUp(self):
self.option = FloatOption()

def test_float_schema(self):
def test_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())
self.assertDictEqual(self.option.schema(), {'type': 'number'})


class TestFloatOptionWithDefault(TestFloatOptionNoDefault):
Expand All @@ -64,8 +65,8 @@ def test_default(self):
"""Tests that the default was set correctly."""
self.assertEqual(self.option.default, 1234.0)

def test_float_schema(self):
def test_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())
self.assertDictEqual(self.option.schema(), {'default': 1234.0, 'type': 'number'})
13 changes: 7 additions & 6 deletions src/freeseer/tests/framework/config/options/test_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# freeseer - vga/presentation capture software
#
# Copyright (C) 2011, 2013 Free and Open Source Software Learning Centre
# Copyright (C) 2011, 2013, 2014 Free and Open Source Software Learning Centre
# http://fosslc.org
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -27,7 +27,8 @@
import tempfile
import unittest

from jsonschema import validate, ValidationError
from jsonschema import validate
from jsonschema import ValidationError

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

def test_string_schema(self):
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({'type': 'string'}, self.option.schema())
self.assertDictEqual(self.option.schema(), {'type': 'string'})


class TestFolderOptionAutoCreate(TestFolderOptionNoDefault):
Expand Down Expand Up @@ -97,8 +98,8 @@ def test_default(self):
"""Tests that the default was set correctly."""
self.assertEqual(self.option.default, '/tmp')

def test_string_schema(self):
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({'default': '/tmp', 'type': 'string'}, self.option.schema())
self.assertDictEqual(self.option.schema(), {'default': '/tmp', 'type': 'string'})
13 changes: 7 additions & 6 deletions src/freeseer/tests/framework/config/options/test_integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# freeseer - vga/presentation capture software
#
# Copyright (C) 2011, 2013 Free and Open Source Software Learning Centre
# Copyright (C) 2011, 2013, 2014 Free and Open Source Software Learning Centre
# http://fosslc.org
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -24,7 +24,8 @@

import unittest

from jsonschema import validate, ValidationError
from jsonschema import validate
from jsonschema import ValidationError

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

def test_integer_schema(self):
def test_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())
self.assertDictEqual(self.option.schema(), {'type': 'integer'})


class TestIntegerOptionWithDefault(TestIntegerOptionNoDefault):
Expand All @@ -64,8 +65,8 @@ def test_default(self):
"""Tests that the default was set correctly."""
self.assertEqual(self.option.default, 1234)

def test_integer_schema(self):
def test_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())
self.assertDictEqual(self.option.schema(), {'default': 1234, 'type': 'integer'})
13 changes: 7 additions & 6 deletions src/freeseer/tests/framework/config/options/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# freeseer - vga/presentation capture software
#
# Copyright (C) 2011, 2013 Free and Open Source Software Learning Centre
# Copyright (C) 2011, 2013, 2014 Free and Open Source Software Learning Centre
# http://fosslc.org
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -24,7 +24,8 @@

import unittest

from jsonschema import ValidationError, validate
from jsonschema import validate
from jsonschema import ValidationError

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

def test_string_schema(self):
def test_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())
self.assertDictEqual(self.option.schema(), {'type': 'string'})


class TestStringOptionWithDefault(TestStringOptionNoDefault):
Expand All @@ -69,8 +70,8 @@ def test_default(self):
"""Tests that the default was set correctly."""
self.assertEqual(self.option.default, 'testing')

def test_string_schema(self):
def test_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())
self.assertDictEqual(self.option.schema(), {'default': 'testing', 'type': 'string'})
8 changes: 4 additions & 4 deletions src/freeseer/tests/framework/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# freeseer - vga/presentation capture software
#
# Copyright (C) 2013 Free and Open Source Software Learning Centre
# Copyright (C) 2013, 2014 Free and Open Source Software Learning Centre
# http://fosslc.org
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -27,7 +27,8 @@
import tempfile
import unittest

from jsonschema import validate, ValidationError
from jsonschema import validate
from jsonschema import ValidationError

from freeseer.framework.config.profile import ProfileManager
from freeseer import settings
Expand Down Expand Up @@ -64,8 +65,7 @@ def test_save(self):
self.assertTrue(os.path.exists(filepath))

def test_schema(self):
"""Tests that the settings Config returns the correct schema based
on all its options."""
"""Tests that the settings Config returns the correct schema based on all its options."""
settings_schema = {
'type': 'object',
'properties': {
Expand Down

0 comments on commit 08784e5

Please sign in to comment.