Exemplo n.º 1
0
 def get_output_format(self,
                       supported_formats: Set[str] = _OUTPUT_FORMAT_VALUES
                       ) -> str:
     output_format = self.get(_OUTPUT_FORMAT_OPTION)
     if output_format in supported_formats:
         return cast(str, output_format)
     raise CmdLineInputError(
         ("Unknown value '{value}' for '{option}' option. Supported "
          "{value_pl} {is_pl}: {supported}").format(
              value=output_format,
              option=_OUTPUT_FORMAT_OPTION,
              value_pl=format_plural(supported_formats, "value"),
              is_pl=format_plural(supported_formats, "is"),
              supported=format_list(list(supported_formats)),
          ))
Exemplo n.º 2
0
 def message(self) -> str:
     return ("Removed {node} {nodes} could not be reached and subsequently "
             "deconfigured. Run 'pcs cluster destroy' on the unreachable "
             "{node}.").format(
                 node=format_plural(self._obj.node_list, "node"),
                 nodes=format_list(self._obj.node_list),
             )
Exemplo n.º 3
0
 def ensure_only_supported(
     self,
     *supported_options: str,
     hint_syntax_changed: bool = False,
     output_format_supported: bool = False,
 ) -> None:
     # --debug is supported in all commands
     supported_options_set = set(supported_options) | {"--debug"}
     if output_format_supported:
         supported_options_set.add(_OUTPUT_FORMAT_OPTION)
     unsupported_options = self._defined_options - supported_options_set
     if unsupported_options:
         pluralize = lambda word: format_plural(unsupported_options, word)
         raise CmdLineInputError(
             "Specified {option} {option_list} {_is} not supported in this "
             "command".format(
                 option=pluralize("option"),
                 option_list=format_list(sorted(unsupported_options)),
                 _is=pluralize("is"),
             ),
             hint="Syntax has changed from previous version. {}".format(
                 SEE_MAN_CHANGES.format("0.11")
             )
             if hint_syntax_changed
             else None,
         )
Exemplo n.º 4
0
 def test_plural_pl(self, mock_is_multiple, mock_add_s):
     mock_is_multiple.return_value = True
     self.assertEqual(
         "plural", tools.format_plural(10, "singular", "plural")
     )
     mock_add_s.assert_not_called()
     mock_is_multiple.assert_called_once_with(10)
Exemplo n.º 5
0
 def message(self) -> str:
     pluralize = lambda word: format_plural(self._obj.node_list, word)
     return ("Remaining cluster {node} {nodes} could not be reached, run "
             "'pcs cluster sync' on any currently online node once the "
             "unreachable {one} become available").format(
                 node=pluralize("node"),
                 nodes=format_list(self._obj.node_list),
                 one=pluralize("one"),
             )
Exemplo n.º 6
0
 def message(self) -> str:
     pluralize = lambda word: format_plural(self._obj.host_list, word)
     return (("{host} {hosts_comma} {_is} not known to pcs, try to "
              "authenticate the {host} using 'pcs host auth {hosts_space}' "
              "command").format(
                  host=pluralize("host"),
                  hosts_comma=format_list(self._obj.host_list),
                  _is=pluralize("is"),
                  hosts_space=" ".join(sorted(self._obj.host_list)),
              ).capitalize())
Exemplo n.º 7
0
 def message(self) -> str:
     return (
         "When {given} {_is} specified, {missing} must be specified as well"
     ).format(
         given=format_list(
             transform(self._obj.mocked_files,
                       _file_role_to_option_translation)),
         _is=format_plural(self._obj.mocked_files, "is"),
         missing=format_list(
             transform(self._obj.required_files,
                       _file_role_to_option_translation)),
     )
Exemplo n.º 8
0
 def ensure_only_supported(self,
                           *supported_options,
                           hint_syntax_changed: bool = False):
     unsupported_options = (
         # --debug is supported in all commands
         self._defined_options - set(supported_options) - set(["--debug"]))
     if unsupported_options:
         pluralize = lambda word: format_plural(unsupported_options, word)
         raise CmdLineInputError(
             "Specified {option} {option_list} {_is} not supported in this "
             "command".format(
                 option=pluralize("option"),
                 option_list=format_list(sorted(unsupported_options)),
                 _is=pluralize("is"),
             ),
             hint="Syntax has changed from previous version. {}".format(
                 SEE_MAN_CHANGES.format("0.11"))
             if hint_syntax_changed else None,
         )
Exemplo n.º 9
0
 def ensure_only_supported(self,
                           *supported_options,
                           hint_syntax_changed: bool = False):
     unsupported_options = (
         # --debug is supported in all commands
         self._defined_options - set(supported_options) - set(["--debug"]))
     if unsupported_options:
         pluralize = lambda word: format_plural(unsupported_options, word)
         raise CmdLineInputError(
             "Specified {option} {option_list} {_is} not supported in this "
             "command".format(
                 option=pluralize("option"),
                 option_list=format_list(sorted(unsupported_options)),
                 _is=pluralize("is"),
             ),
             # Print error messages which point users to the changes section
             # in pcs manpage.
             # To be removed in the next significant version.
             hint=(HINT_SYNTAX_CHANGE if hint_syntax_changed else None),
         )
Exemplo n.º 10
0
 def test_do_sg(self):
     self.assertEqual("does", tools.format_plural("he", "does"))
Exemplo n.º 11
0
 def test_is_pl(self, mock_is_multiple, mock_add_s):
     mock_is_multiple.return_value = True
     self.assertEqual("are", tools.format_plural(2, "is"))
     mock_add_s.assert_not_called()
     mock_is_multiple.assert_called_once_with(2)
Exemplo n.º 12
0
 def test_have_sg(self, mock_is_multiple, mock_add_s):
     mock_is_multiple.return_value = False
     self.assertEqual("has", tools.format_plural("he", "has"))
     mock_add_s.assert_not_called()
     mock_is_multiple.assert_called_once_with("he")
Exemplo n.º 13
0
 def test_have_pl(self, mock_is_multiple, mock_add_s):
     mock_is_multiple.return_value = True
     self.assertEqual("have", tools.format_plural(["he", "she"], "has"))
     mock_add_s.assert_not_called()
     mock_is_multiple.assert_called_once_with(["he", "she"])
Exemplo n.º 14
0
 def test_regular_sg(self, mock_is_multiple, mock_add_s):
     mock_is_multiple.return_value = False
     self.assertEqual("greeting", tools.format_plural(1, "greeting"))
     mock_add_s.assert_not_called()
     mock_is_multiple.assert_called_once_with(1)
Exemplo n.º 15
0
 def test_regular_pl(self):
     self.assertEqual("greetings", tools.format_plural(10, "greeting"))
Exemplo n.º 16
0
 def test_plural_pl(self):
     self.assertEqual(
         "plural", tools.format_plural(10, "singular", "plural")
     )
Exemplo n.º 17
0
 def test_have_pl(self):
     self.assertEqual("have", tools.format_plural(["he", "she"], "has"))
Exemplo n.º 18
0
 def test_have_sg(self):
     self.assertEqual("has", tools.format_plural("he", "has"))
Exemplo n.º 19
0
 def test_do_pl(self):
     self.assertEqual("do", tools.format_plural(["he", "she"], "does"))
Exemplo n.º 20
0
 def test_is_pl(self):
     self.assertEqual("are", tools.format_plural(2, "is"))
Exemplo n.º 21
0
 def test_is_sg(self):
     self.assertEqual("is", tools.format_plural(1, "is"))
Exemplo n.º 22
0
 def test_regular_pl(self, mock_is_multiple, mock_add_s):
     mock_add_s.return_value = "greetings"
     mock_is_multiple.return_value = True
     self.assertEqual("greetings", tools.format_plural(10, "greeting"))
     mock_add_s.assert_called_once_with("greeting")
     mock_is_multiple.assert_called_once_with(10)