def check(self):
<EOL>expected_positions = self._machine.needle_positions<EOL>expected_row_length = self._machine.number_of_needles<EOL>for row_index, row in enumerate(self._rows):<EOL><INDENT>if len(row) != expected_row_length:<EOL><INDENT>message = _ROW_LENGTH_ERROR_MESSAGE.format(<EOL>row_index, len(row), expected_row_length)<EOL>raise ValueError(message)<EOL><DEDENT>for needle_index, needle_position in enumerate(row):<EOL><INDENT>if needle_position not in expected_positions:<EOL><INDENT>message = _NEEDLE_POSITION_ERROR_MESSAGE.format(<EOL>row_index, needle_index, repr(needle_position),<EOL>"<STR_LIT:U+002CU+0020>".join(map(repr, expected_positions)))<EOL>raise ValueError(message)<EOL><DEDENT><DEDENT><DEDENT>
Check for validity.

        :raises ValueError:

          - if not all lines are as long as the :attr:`number of needles
            <AYABInterface.machines.Machine.number_of_needles>`
          - if the contents of the rows are not :attr:`needle positions
            <AYABInterface.machines.Machine.needle_positions>`