Beispiel #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")
Beispiel #2
0
 def create_supports(self, l_id):
     for i in range(random.randint(1, 10)):
         s_id = Choices.e_id_gen("SUPPORTS",
                                 len(self.graph.tuples["SUPPORTS"]))
         lieu = util.create_location(self.graph.boundaries)
         self.graph.tuples["EQUIPEMENTS"].append([s_id])
         self.graph.tuples["SUPPORTS"].append([
             s_id, l_id,
             util.create_location(self.graph.boundaries),
             random.choice(Choices.supports)[0]
         ])
Beispiel #3
0
 def add_tuples(self):
     self.categorie = self.random_categorie()
     self.p_id = Choices.e_id_gen(self.categorie,
                                  len(self.graph.tuples[self.categorie]))
     lieu = util.create_location(self.graph.boundaries)
     self.graph.tuples["EQUIPEMENTS"].append([self.p_id])
     self.graph.tuples["POSTES"].append([self.p_id, lieu])
     self.graph.tuples[self.categorie].append([self.p_id])
     if self.categorie == "POINTSRACCORDEMENT":
         a_id = gen_abonnnes(self.p_id, self.graph)
         self.graph.tuples[self.categorie][-1] += [a_id]
Beispiel #4
0
 def add_tuple(self, init_node):
     dest_node = self.graph.add_node(init_node)
     l_id = Choices.e_id_gen("LIGNES", len(self.graph.tuples["LIGNES"]))
     self.create_supports(l_id)
     self.graph.tuples["EQUIPEMENTS"].append([l_id])
     self.graph.tuples["LIGNES"].append([
         l_id,
         random.randint(500, 10000),
         random.randint(500, 10000),
         random.randint(10, 10000), init_node, dest_node,
         random.choice(Choices.lignes)
     ])
Beispiel #5
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")])
Beispiel #6
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
Beispiel #7
0
 def create_ids(self):
     c_id = Choices.e_id_gen("CENTRALES",
                             len(self.graph.tuples["CENTRALES"]))
     s_id = Choices.e_id_gen("SOURCES", len(self.graph.tuples["SOURCES"]))
     p_id = s_id
     return c_id, s_id, p_id
Beispiel #8
0
"""
This module contains the choices definition for settings required
for the build master to run.
"""

from choices import Choices

from loader import load_settings

#----------------------------------------------------------------------
# Define the Settings
#----------------------------------------------------------------------
c = Choices()
c.define('title', type=str, help="Buildmaster title")
c.define('title_url', type=str, help="URL for title page")
c.define('buildbot_url', type=str, help="URL to the buildbot master.")
c.define('slaves', type=str, help="A list of the slave machines. The format should be name:password,name:password,...")
c.define('web_port', type=int, help="Port to listen on for web service.")

#----------------------------------------------------------------------
# Load the Settings
#----------------------------------------------------------------------
options = load_settings(c, "master")
Beispiel #9
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"),
))
Beispiel #10
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")
Beispiel #11
0
 def test_cannot_use_class_names(self):
     for name in ('constants', 'choices'):
         with self.assertRaises(AssertionError):
             Choices([
                 (name, name),
             ])
Beispiel #12
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):
Beispiel #13
0
"""
This module contains the choices definition for settings required
for the build master to run.
"""

from choices import Choices

from loader import load_settings

#----------------------------------------------------------------------
# Define the Settings
#----------------------------------------------------------------------
c = Choices()
c.define('title', type=str, help="Buildmaster title")
c.define('title_url', type=str, help="URL for title page")
c.define('buildbot_url', type=str, help="URL to the buildbot master.")
c.define(
    'slaves',
    type=str,
    help=
    "A list of the slave machines. The format should be name:password,name:password,..."
)
c.define('web_port', type=int, help="Port to listen on for web service.")
c.define('http_users', type=str, help="username:password list of users.")

#----------------------------------------------------------------------
# Load the Settings
#----------------------------------------------------------------------
options = load_settings(c, "master")
Beispiel #14
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")
Beispiel #15
0
def _load_choices(path: str) -> Choices:
    with open(path) as f:
        rules = load(f)
    return Choices(rules)