def test_format_should_dump_full_config_even_if_file_overrides_only_one( self, stdout): self.assertSuccess( execute_cmake_tidy(command='format', arguments=['--dump-config', 'file.txt'])) normalized_output = normalize(stdout.getvalue()) verify(normalized_output, self.reporter)
def test_format_should_dump_config_only_configuration_to_stdout_by_default( self, stdout): self.assertSuccess( execute_cmake_tidy(command='format', arguments=['--dump-config', 'dummy.txt'])) normalized_output = normalize(stdout.getvalue()) verify(normalized_output, self.reporter)
def test_format_should_fail_with_warning_about_incorrect_settings_when_dump_invoked( self, stdout): self.assertFail( execute_cmake_tidy(command='format', arguments=['--dump-config', 'file.txt'])) normalized_output = normalize(stdout.getvalue()) verify(normalized_output, self.reporter)
def test_format_should_fail_with_warning_about_incorrect_settings_when_trying_to_format( self, stdout): self.assertFail( execute_cmake_tidy(command='format', arguments=[get_input_file('arguments.cmake')])) normalized_output = normalize(stdout.getvalue()) verify(normalized_output, self.reporter)
def test_format_inplace_with_error_should_inform_about_failure_and_keep_initial_file( self, write, stderr): self.assertFail( execute_cmake_tidy( command='format', arguments=['-i', get_input_file('incorrect_file.cmake')])) write.assert_not_called() normalized_output = normalize(stderr.getvalue()) verify(normalized_output, self.reporter)
def test_format_should_return_error_when_file_is_read_only_and_inplace_param_is_used( self, stderr): self.assertFail( execute_cmake_tidy( command='format', arguments=['-i', get_input_file('arguments.cmake')])) normalized_output = normalize(stderr.getvalue()) normalized_output = re.sub(r'File .*arguments', 'File <path>arguments', normalized_output) verify(normalized_output, self.reporter)
def test_format_should_provide_unified_diff_to_stdout(self, stdout): self.assertSuccess( execute_cmake_tidy( command='format', arguments=['--diff', get_input_file('arguments.cmake')])) normalized_output = normalize(stdout.getvalue()) normalized_output = self.__replace_with_fake_path( 'arguments.cmake', normalized_output) verify(normalized_output, self.reporter)
def test_format_should_dump_config_from_current_cwd(self, stdout): fake_path = Path(self.temp_directory.name) / 'abc' self.create_config_file(fake_path, '{"line_length": 20}') with mock.patch('pathlib.Path.cwd', return_value=fake_path): self.assertSuccess( execute_cmake_tidy(command='format', arguments=['--dump-config'])) received_settings = json.loads(stdout.getvalue()) self.assertFalse(self.default_settings == received_settings) self.assertEqual(20, received_settings.get('line_length'))
def test_format_multiple_files_verbose(self, stdout, write): arguments = [ '-i', '--verbose', get_input_file('arguments.cmake'), get_input_file('comments.cmake') ] self.assertSuccess( execute_cmake_tidy(command='format', arguments=arguments)) self.assertEqual(2, write.call_count) self.assertIn(get_input_file('arguments.cmake'), stdout.getvalue()) self.assertIn(get_input_file('comments.cmake'), stdout.getvalue())
def test_format_should_dump_config_from_one_of_input_file_parents_location( self, stdout): fake_path = Path(self.temp_directory.name) / 'some_dir' self.create_config_file(fake_path, '{"line_length": 33}') input_filename = str((fake_path / 'another' / 'test.cmake').absolute()) self.assertSuccess( execute_cmake_tidy(command='format', arguments=['--dump-config', input_filename])) received_settings = json.loads(stdout.getvalue()) self.assertFalse(self.default_settings == received_settings) self.assertEqual(33, received_settings.get('line_length'))
def test_format_inplace_simple_file_with_verbose_option( self, stdout, write): self.assertSuccess( execute_cmake_tidy(command='format', arguments=[ '-i', '--verbose', get_input_file('arguments.cmake') ])) write.assert_called_once() self.assertIn(get_input_file('arguments.cmake'), stdout.getvalue()) normalized_output = normalize(write.call_args[0][1]) verify(normalized_output, self.reporter)
def format_file(self, file: str): self.assertSuccess( execute_cmake_tidy(command='format', arguments=[get_input_file(file)]))
def test_analyze_should_correctly_print_version(self, stdout): self.assertSuccess( execute_cmake_tidy(None, arguments=['-v', 'analyze'])) verify(mangle_version(stdout.getvalue()), self.reporter)
def test_analyze_command_help_shown(self, stdout): self.assertSuccess( execute_cmake_tidy(command='analyze', arguments=['--help'])) normalized_output = normalize(stdout.getvalue()) verify(normalized_output, self.reporter)
def test_version_argument_should_provide_correct_tool_version( self, stdout): self.assertSuccess(execute_cmake_tidy(command=None, arguments=['-v'])) normalized_output = normalize(stdout.getvalue()) verify(normalized_output, self.reporter)
def test_incorrect_command_should_print_error_with_usage_help( self, stderr): self.assertFail(execute_cmake_tidy(command='invalid', arguments=[])) normalized_output = normalize(stderr.getvalue()) verify(normalized_output, self.reporter)
def test_format_should_dump_default_config_when_no_config_available_in_cwd( self, stdout): self.assertSuccess( execute_cmake_tidy(command='format', arguments=['--dump-config'])) self.assertDictEqual(self.default_settings, json.loads(stdout.getvalue()))