예제 #1
0
    def test_parse_opens_file_path(self, mock_isfile):
        mock_isfile.return_value = True

        with patch('builtins.open', mock_open(read_data='data')) as open_:
            YamlFileParser.parse(self.input_file_path)

            open_.assert_called_once_with(self.input_file_path, 'r')
예제 #2
0
    def run(self, input_path: str, output_path: str) -> None:
        """ This method defines and controls the execution of Symboard given the
        parameters with which Symboard was called. it will parse the given input
        file, create a keylayout according to that spec, and write this
        keylayout as an XML file to the specified output path.

        Args:
            input_path (str): The path to the file containing the specification
                from which to create a keylayout.
            output_path (str): The path to which the output keylayout is to be
                written.
        """
        logging.info(f'Parsing the contents from {input_path}.')

        keylayout_spec = YamlFileParser.parse(
            input_path,
            case_sensitive=True,
        )

        logging.info(f'Creating the keyboard object from the specification.')

        keylayout = keylayout_from_spec(keylayout_spec)

        logging.info(
            f'Trying to write the keylayout to disk at {output_path}.')

        file_writer = KeylayoutXMLFileWriter()
        file_writer.write(keylayout, output_path)
예제 #3
0
    def test_parse_not_case_sensitive(self, mock_isfile, mock_safe_load):
        expected = self.lower_spec

        mock_isfile.return_value = True
        mock_safe_load.return_value = self.spec

        with patch('builtins.open', mock_open(read_data='data')):
            actual = YamlFileParser.parse(self.input_file_path,
                                          case_sensitive=False)

        self.assertEqual(expected, actual)
예제 #4
0
    def test_parse_raises_error_if_exception_occurs(self, mock_isfile):
        mock_isfile.side_effect = ParserException()

        with patch('builtins.open', mock_open(read_data='data')) as open_:
            with self.assertRaises(ParserException):
                results = YamlFileParser.parse(object)
예제 #5
0
    def test_parse_raises_error_if_not_isfile(self, mock_isfile):
        mock_isfile.return_value = False

        with patch('builtins.open', mock_open(read_data='data')) as open_:
            with self.assertRaises(ParserException):
                results = YamlFileParser.parse('')
예제 #6
0
 def test__lower_dict(self):
     expected = self.lower_spec
     self.assertEqual(expected, YamlFileParser._lower_dict(self.spec))
예제 #7
0
    def test__try_lower(self):
        test_inputs = ['lower', 'CAPS', 1, True]
        expected = ['lower', 'caps', 1, True]

        for i, input_ in enumerate(test_inputs):
            self.assertEqual(expected[i], YamlFileParser._try_lower(input_))