From d9a5ba8add97fb74ec8a63f200d8769d97bb54db Mon Sep 17 00:00:00 2001 From: Frank Hoffmann <15r10nk-git@polarbit.de> Date: Fri, 25 Oct 2024 19:19:41 +0200 Subject: [PATCH] fix src-layout problems and add syntax heighlight --- mutmut/__main__.py | 20 ++++++++++++-------- mutmut/result_browser_layout.tcss | 9 +++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/mutmut/__main__.py b/mutmut/__main__.py index 542bc6a0..f4e16e77 100644 --- a/mutmut/__main__.py +++ b/mutmut/__main__.py @@ -266,7 +266,8 @@ def create_mutants_for_file(filename, output_path): exit(1) source_file_mutation_data = SourceFileMutationData(path=filename) - module_name = str(filename)[:-len(filename.suffix)].replace(os.sep, '.') + + module_name = strip_prefix(str(filename),prefix="src/")[:-len(filename.suffix)].replace(os.sep, '.') source_file_mutation_data.exit_code_by_key = { '.'.join([module_name, x]).replace('.__init__.', '.'): None for x in mutant_names @@ -1067,7 +1068,7 @@ def collect_source_file_mutation_data(*, mutant_names): source_file_mutation_data_by_path[str(path)] = m mutants = [ - (m, mutant_name, result) + (m, mutant_name.replace("src.",""), result) for path, m in source_file_mutation_data_by_path.items() for mutant_name, result in m.exit_code_by_key.items() ] @@ -1446,7 +1447,9 @@ def browse(): from textual.containers import Container from textual.widgets import Footer from textual.widgets import DataTable - from textual.widgets import TextArea + from textual.widgets import Static + from textual.widget import Widget + from rich.syntax import Syntax class ResultBrowser(App): loading_id = None @@ -1473,7 +1476,8 @@ def compose(self): with Container(classes='container'): yield DataTable(id='files') yield DataTable(id='mutants') - yield TextArea(id='diff_view') + with Widget(id="diff_view_widget"): + yield Static(id='diff_view') yield Footer() def on_mount(self): @@ -1532,9 +1536,9 @@ def on_data_table_row_highlighted(self, event): assert event.data_table.id == 'mutants' diff_view = self.query_one('#diff_view') if event.row_key.value is None: - diff_view.text = '' + diff_view.update('') else: - diff_view.text = '' + diff_view.update('') self.loading_id = event.row_key.value def load_thread(): @@ -1542,9 +1546,9 @@ def load_thread(): try: d = get_diff_for_mutant(event.row_key.value) if event.row_key.value == self.loading_id: - diff_view.text = d + diff_view.update(Syntax(d,"diff")) except Exception as e: - diff_view.text = f'<{type(e)} {e}>' + diff_view.update(f'<{type(e)} {e}>') t = Thread(target=load_thread) t.start() diff --git a/mutmut/result_browser_layout.tcss b/mutmut/result_browser_layout.tcss index b40dda59..d3672f88 100644 --- a/mutmut/result_browser_layout.tcss +++ b/mutmut/result_browser_layout.tcss @@ -24,3 +24,12 @@ DataTable:focus .datatable--cursor { color: black; background: orange; } + +#diff_view_widget{ + height: 50%; + border: solid; + overflow-y: scroll; +} + +#diff_view{ +}