Beispiel #1
0
def test_impossible(changes):
    # All supplied changes are physically impossible and should trigger an
    # exception.
    values = exact.copy()
    values.update(changes)
    with pytest.raises(ValueError):
        Cabinet(**values)
Beispiel #2
0
def test_possible(values):
    # Test that all attributes given as arguments get set correctly and that all
    # supplied situations do not get rejected as impossible.
    c = Cabinet(**values)
    for name, value in iteritems(values):
        if name in board_wire_offset_fields:
            assert c.board_wire_offset[board_wire_offset_fields[name]] == value
        else:
            assert hasattr(c, name)
            assert getattr(c, name) == value
Beispiel #3
0
def get_cabinets_from_args(parser, args):
	"""For use with add_cabinet_args (and optionally add_topology_args).
	
	Get information about the dimensions of the cabinets in the system from the
	supplied arguments.
	
	Returns
	-------
	(:py:class:`spinner.cabinet.Cabinet`, num_frames)
		num_frames is the number of frames (per cabinet) to actually fill with
		boards.
	"""
	kwargs = {
		kw: tuple(getattr(args, kw))
		    if type(getattr(args, kw)) is list
		    else getattr(args, kw)
		for kw in [
			"board_dimensions",
			"board_wire_offset_south_west",
			"board_wire_offset_north_east",
			"board_wire_offset_east",
			"board_wire_offset_west",
			"board_wire_offset_north",
			"board_wire_offset_south",
			"inter_board_spacing",
			"boards_per_frame",
			"frame_dimensions",
			"frame_board_offset",
			"inter_frame_spacing",
			"frames_per_cabinet",
			"cabinet_dimensions",
			"cabinet_frame_offset",
			"inter_cabinet_spacing",
		]
	}
	
	# Work out number of boards to allow checking of num_cabinets and num_frames
	# (only possible if topology args are present)
	if hasattr(args, "num_boards") and args.num_boards is not None:
		num_boards = args.num_boards
	elif hasattr(args, "triads") and args.triads is not None:
		num_boards = 3 * args.triads[0] * args.triads[1]
	else:
		num_boards = None  # unknown!
	
	if args.num_cabinets is None and args.num_frames is None:
		# Try to pick an sensible default value if number of boards is known,
		# otherwise default to a single cabinet system.
		if num_boards is not None:
			num_cabinets, num_frames = min_num_cabinets(num_boards,
			                                            args.frames_per_cabinet,
			                                            args.boards_per_frame)
		else:
			num_cabinets = 1
			num_frames = args.frames_per_cabinet
	else:
		# Default to 1 cabinet
		if args.num_cabinets is None:
			num_cabinets = 1
		else:
			num_cabinets = args.num_cabinets
		
		# Default to the full number of frames
		if args.num_frames is None:
			num_frames = args.frames_per_cabinet
		else:
			num_frames = args.num_frames
			if num_frames > args.frames_per_cabinet:
				parser.error("more frames specified than fit in a cabinet")
			if num_cabinets > 1 and num_frames != args.frames_per_cabinet:
				parser.error("--num-frames must equal --frames-per-cabinet "
				             "when there is more than one cabinet")
	
	# Check that the number of cabinets/frames is sufficient for the number of
	# boards present (if known)
	if (num_boards is not None and
	    num_cabinets * num_frames * args.boards_per_frame < num_boards):
		parser.error("not enough cabinets/frames available for {} "
		             "boards".format(num_boards))
	
	kwargs["num_cabinets"] = num_cabinets
	
	try:
		return (Cabinet(**kwargs), num_frames)
	except ValueError as e:
		parser.error(e.args[0])
Beispiel #4
0
def test_cabinet_get_dimensions(kwargs, dimen):
    c = Cabinet(**exact)
    assert c.get_dimensions(**kwargs) == dimen
Beispiel #5
0
def test_cabinet_get_position_opposite(args, pos):
    c = Cabinet(**exact)
    assert c.get_position_opposite(*args) == pos
def cabinet():
    from example_cabinet_params import real
    from spinner.cabinet import Cabinet
    return Cabinet(**real)
def test_cabinet_get_position(args, pos):
	c = Cabinet(**exact)
	assert c.get_position(*args) == pos
def test_cabinet_get_dimensions(kwargs, dimen):
	c = Cabinet(**exact)
	assert c.get_dimensions(**kwargs) == dimen
from collections import defaultdict

from six import itervalues

from spinner.diagrams.machine import normalise_slice, MachineDiagram

from spinner.cabinet import Cabinet

from spinner.topology import Direction

from example_cabinet_params import real, unique


# Cabinet used in all examples (instantiated like this rather than using a
# fixture since it is used in test parameters)
c = Cabinet(**real)



@pytest.mark.parametrize("orig,new", [# Constants
                                      (0, slice(0, 1)),
                                      (1, slice(1, 2)),
                                      # None
                                      (None, slice(0, 10)),
                                      # Complete slices
                                      (slice(0, 2), slice(0, 2)),
                                      (slice(4, 8), slice(4, 8)),
                                      # Open-ended slices
                                      (slice(0, None), slice(0, 10)),
                                      (slice(2, None), slice(2, 10)),
                                      (slice(None, 2), slice(0, 2)),
from spinner.topology import Direction

from spinner.scripts import arguments

from spinner.scripts.wiring_diagram import \
 main, add_diagram_arguments, get_diagram_arguments

from spinner.diagrams.machine import MachineDiagram

from spinner.cabinet import Cabinet

from example_cabinet_params import real

# Cabinet used in all examples (instantiated like this rather than using a
# fixture since it is used in test parameters)
c = Cabinet(**real)


@pytest.mark.parametrize(
    "argstring,to_check",
    [  # Wire thickness
        ("-n 3", {
            "wire_thickness": "normal"
        }),
        ("-n 3 --wire-thickness normal", {
            "wire_thickness": "normal"
        }),
        ("-n 3 --wire-thickness thin", {
            "wire_thickness": "thin"
        }),
        ("-n 3 --wire-thickness thick", {