Ejemplo n.º 1
0
    def test_python_keywords_and_numbers(self):
        special = Choices([("id", "ID"), ("1", "One"), ("in", "IN"),
                           ("xx", "XX")])

        self.assertEqual(special._id, "id")
        self.assertEqual(special._1, "1")
        self.assertEqual(special._in, "in")

        # Underscore access should only work for keywords and numbers
        self.assertRaises(AttributeError, getattr, special, "_xx")
Ejemplo n.º 2
0
    def test_hyphens_and_spaces(self):
        special = Choices([
            ("en-GB", "ID"),
            ("my thing", "One"),
        ])

        self.assertEqual(special.en_GB, "en-GB")
        self.assertEqual(special.my_thing, "my thing")

        # Check that we don't allow conflicting choices
        self.assertRaises(ValueError, Choices, [("en-GB", "1"),
                                                ("en_GB", "2")])
Ejemplo n.º 3
0
def test_choices():
    with open('choices.json') as f:
        _RULES = load(f)

    choices = Choices(_RULES)

    assert choices.get_sorted_ids() == [(1, 'rock'), (2, 'paper'),
                                        (3, 'scissors'), (4, 'spock'),
                                        (5, 'lizard')]

    winning_tuples = (('scissors', 'paper'), ('paper', 'rock'),
                      ('rock', 'lizard'), ('lizard', 'spock'),
                      ('spock', 'scissors'), ('scissors', 'lizard'),
                      ('lizard', 'paper'), ('paper', 'spock'),
                      ('spock', 'rock'), ('rock', 'scissors'))

    assert choices.decide_game_names('spock', 'spock') == 0

    for win, lose in winning_tuples:
        assert choices.decide_game_names(win, lose) == -1
        assert choices.decide_game_names(lose, win) == 1
Ejemplo n.º 4
0
# THIRD PARTY
from choices import Choices

CONSTITUENCIES = Choices((
    # TODO: add the other 648 consituencies into here!
    ("Bristol West", "Bristol West"),
    ("Whitney", "Whitney"),
))

PARTIES = Choices((
    # In *alphabetical* order!
    # Names are as per http://www.parliament.uk/mps-lords-and-offices/mps/current-state-of-the-parties/
    ("Conservative", "Conservative"),
    ("Democratic Unionist Party", "Democratic Unionist Party"),
    ("Green", "Green"),
    ("Independent", "Independent"),
    ("Labour", "Labour"),
    ("Liberal Democrat", "Liberal Democrat"),
    ("Plaid Cymru", "Plaid Cymru"),
    ("Scotish National Party", "Scotish National Party"),
    ("Sinn Fein", "Sinn Fein"),
    ("Social Democratic & Labour Party", "Social Democratic & Labour Party"),
    ("Speaker", "Speaker"),
    ("UK Independence", "UK Independence"),
    ("Ulster Unionist Party", "Ulster Unionist Party"),
))
Ejemplo n.º 5
0
"""
This module contains the choices definition for settings required for the
build slave to run.
"""

from choices import Choices

from loader import load_settings

#----------------------------------------------------------------------
# Define the Settings
#----------------------------------------------------------------------
c = Choices()
c.define("master_host", type=str, help="Host of the build master.")
c.define("master_port",
         type=int,
         help="Port that is listening or build masters.")
c.define("name", type=str, help="Name of the slave machine.")
c.define("password",
         type=str,
         help="Password for the slave machine to communicate with the master.")

#----------------------------------------------------------------------
# Load the Settings
#----------------------------------------------------------------------
options = load_settings(c, "slave")
Ejemplo n.º 6
0
 def test_cannot_use_class_names(self):
     for name in ('constants', 'choices'):
         with self.assertRaises(AssertionError):
             Choices([
                 (name, name),
             ])
Ejemplo n.º 7
0
import unittest

from choices import Choices

colours = Choices([
    ('red', 'strawberry'),
    ('white', 'vanilla'),
    ('black', 'chocolate'),
])


class ChoicesTestCase(unittest.TestCase):
    def test_create_choices(self):
        self.assertEqual(colours.red, 'red')
        self.assertEqual(colours.white, 'white')
        self.assertEqual(colours.black, 'black')

    def test_hyphens_and_spaces(self):
        special = Choices([
            ("en-GB", "ID"),
            ("my thing", "One"),
        ])

        self.assertEqual(special.en_GB, "en-GB")
        self.assertEqual(special.my_thing, "my thing")

        # Check that we don't allow conflicting choices
        self.assertRaises(ValueError, Choices, [("en-GB", "1"),
                                                ("en_GB", "2")])

    def test_python_keywords_and_numbers(self):
Ejemplo n.º 8
0
def _load_choices(path: str) -> Choices:
    with open(path) as f:
        rules = load(f)
    return Choices(rules)