Skip to content

Commit

Permalink
fix src-layout problems and add syntax heighlight
Browse files Browse the repository at this point in the history
  • Loading branch information
15r10nk committed Oct 25, 2024
1 parent 1465724 commit d9a5ba8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
20 changes: 12 additions & 8 deletions mutmut/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
]
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -1532,19 +1536,19 @@ 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 = '<loading...>'
diff_view.update('<loading...>')
self.loading_id = event.row_key.value

def load_thread():
read_config()
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()
Expand Down
9 changes: 9 additions & 0 deletions mutmut/result_browser_layout.tcss
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,12 @@ DataTable:focus .datatable--cursor {
color: black;
background: orange;
}

#diff_view_widget{
height: 50%;
border: solid;
overflow-y: scroll;
}

#diff_view{
}

0 comments on commit d9a5ba8

Please sign in to comment.