fix e2etest

This commit is contained in:
Will McGugan
2022-07-29 11:01:58 +01:00
parent 547b8531a1
commit 67091ef2df
4 changed files with 195 additions and 132 deletions

View File

@@ -14,7 +14,8 @@ if len(sys.argv) > 1:
if len(sys.argv) > 2: if len(sys.argv) > 2:
script_time_to_live = float(sys.argv[2]) script_time_to_live = float(sys.argv[2])
e2e_root = Path(__file__).parent e2e_root = Path(__file__).parent / "test_apps"
print(e2e_root)
completed_process = None completed_process = None
@@ -22,7 +23,7 @@ completed_process = None
def launch_sandbox_script(python_file_name: str) -> None: def launch_sandbox_script(python_file_name: str) -> None:
global completed_process global completed_process
command = f"{sys.executable} ./test_apps/{shlex.quote(python_file_name)}.py" command = f"{sys.executable} {shlex.quote(python_file_name)}.py"
print(f"Launching command '{command}'...") print(f"Launching command '{command}'...")
try: try:
completed_process = subprocess.run( completed_process = subprocess.run(

View File

@@ -2,27 +2,46 @@
* { * {
transition: color 300ms linear, background 300ms linear; transition: color 300ms linear, background 300ms linear;
} }
*:hover {
/* tint: 30% red;
/* outline: heavy red; */
}
App > Screen { App > Screen {
layout: dock;
docks: side=left/1;
background: $surface; background: $surface;
color: $text-surface; color: $text-surface;
layers: sidebar;
color: $text-background;
background: $background;
layout: vertical;
} }
DataTable {
/*border:heavy red;*/
/* tint: 10% green; */
/* opacity: 50%; */
padding: 1;
margin: 1 2;
height: 12;
}
#sidebar { #sidebar {
color: $text-primary; color: $text-panel;
background: $primary; background: $panel;
dock: side; dock: left;
width: 30; width: 30;
offset-x: -100%; offset-x: -100%;
layout: dock;
transition: offset 500ms in_out_cubic; transition: offset 500ms in_out_cubic;
layer: sidebar;
} }
#sidebar.-active { #sidebar.-active {
@@ -30,72 +49,67 @@ App > Screen {
} }
#sidebar .title { #sidebar .title {
height: 3; height: 1;
background: $primary-darken-2; background: $primary-background-darken-1;
color: $text-primary-darken-2 ; color: $text-primary-background-darken-1;
border-right: outer $primary-darken-3; border-right: wide $background;
content-align: center middle; content-align: center middle;
} }
#sidebar .user { #sidebar .user {
height: 8; height: 8;
background: $primary-darken-1; background: $panel-darken-1;
color: $text-primary-darken-1; color: $text-panel-darken-1;
border-right: outer $primary-darken-3; border-right: wide $background;
content-align: center middle; content-align: center middle;
} }
#sidebar .content { #sidebar .content {
background: $primary; background: $panel-darken-2;
color: $text-primary; color: $text-surface;
border-right: outer $primary-darken-3; border-right: wide $background;
content-align: center middle; content-align: center middle;
} }
#header { #header {
color: $text-primary-darken-1; color: $text-secondary-background;
background: $primary-darken-1; background: $secondary-background;
height: 3; height: 1;
content-align: center middle; content-align: center middle;
}
dock: top;
#content {
color: $text-background;
background: $background;
layout: vertical;
overflow-y: scroll;
} }
Tweet { Tweet {
height: 12; height:12;
width: 80; width: 100%;
margin: 1 3;
background: $panel; background: $panel;
color: $text-panel; color: $text-panel;
layout: vertical; layout: vertical;
/* border: outer $primary; */ /* border: outer $primary; */
padding: 1; padding: 1;
border: wide $panel-darken-2; border: wide $panel;
overflow-y: scroll; overflow: auto;
/* scrollbar-gutter: stable; */
align-horizontal: center; align-horizontal: center;
box-sizing: border-box;
} }
.scrollable { .scrollable {
width: 80;
overflow-y: scroll; overflow-y: scroll;
max-width:80; margin: 1 2;
height: 20; height: 20;
align-horizontal: center; align-horizontal: center;
layout: vertical; layout: vertical;
} }
.code { .code {
height: auto;
height: 34;
width: 100%;
} }
@@ -110,9 +124,12 @@ TweetBody {
width: 100%; width: 100%;
background: $panel; background: $panel;
color: $text-panel; color: $text-panel;
height:20; height: auto;
padding: 0 1 0 0; padding: 0 1 0 0;
}
Tweet.scroll-horizontal TweetBody {
width: 350;
} }
.button { .button {
@@ -123,11 +140,11 @@ TweetBody {
/* border-top: hidden $accent-darken-3; */ /* border-top: hidden $accent-darken-3; */
border: tall $accent-darken-2; border: tall $accent-darken-2;
/* border-left: tall $accent-darken-1; */ /* border-left: tall $accent-darken-1; */
/* padding: 1 0 0 0 ; */ /* padding: 1 0 0 0 ; */
transition: background 200ms in_out_cubic, color 300ms in_out_cubic; transition: background 400ms in_out_cubic, color 400ms in_out_cubic;
} }
@@ -138,18 +155,19 @@ TweetBody {
height: 3; height: 3;
border: tall $accent-darken-1; border: tall $accent-darken-1;
/* border-left: tall $accent-darken-3; */ /* border-left: tall $accent-darken-3; */
} }
#footer { #footer {
color: $text-accent; color: $text-accent;
background: $accent; background: $accent;
height: 1; height: 1;
border-top: hkey $accent-darken-2;
content-align: center middle; content-align: center middle;
dock:bottom;
} }
@@ -159,58 +177,60 @@ TweetBody {
OptionItem { OptionItem {
height: 3; height: 3;
background: $primary; background: $panel;
transition: background 100ms linear; border-right: wide $background;
border-right: outer $primary-darken-2; border-left: blank;
border-left: hidden;
content-align: center middle; content-align: center middle;
} }
OptionItem:hover { OptionItem:hover {
height: 3; height: 3;
color: $accent; color: $text-primary;
background: $primary-darken-1; background: $primary-darken-1;
/* border-top: hkey $accent2-darken-3; /* border-top: hkey $accent2-darken-3;
border-bottom: hkey $accent2-darken-3; */ border-bottom: hkey $accent2-darken-3; */
text-style: bold; text-style: bold;
border-left: outer $accent-darken-2; border-left: outer $secondary-darken-2;
} }
Error { Error {
width: 80; width: 100%;
height:3; height:3;
background: $error; background: $error;
color: $text-error; color: $text-error;
border-top: hkey $error-darken-2; border-top: tall $error-darken-2;
border-bottom: hkey $error-darken-2; border-bottom: tall $error-darken-2;
margin: 1 3;
padding: 0;
text-style: bold; text-style: bold;
align-horizontal: center; align-horizontal: center;
} }
Warning { Warning {
width: 80; width: 100%;
height:3; height:3;
background: $warning; background: $warning;
color: $text-warning-fade-1; color: $text-warning-fade-1;
border-top: hkey $warning-darken-2; border-top: tall $warning-darken-2;
border-bottom: hkey $warning-darken-2; border-bottom: tall $warning-darken-2;
margin: 1 2;
text-style: bold; text-style: bold;
align-horizontal: center; align-horizontal: center;
} }
Success { Success {
width: 80; width: 100%;
height:3;
height:auto;
box-sizing: border-box; box-sizing: border-box;
background: $success-lighten-3; background: $success;
color: $text-success-lighten-3-fade-1; color: $text-success-fade-1;
border-top: hkey $success;
border-bottom: hkey $success; border-top: hkey $success-darken-2;
margin: 1 2; border-bottom: hkey $success-darken-2;
text-style: bold;
text-style: bold ;
align-horizontal: center; align-horizontal: center;
} }

View File

@@ -1,13 +1,12 @@
from pathlib import Path
from rich.console import RenderableType from rich.console import RenderableType
from rich.style import Style
from rich.syntax import Syntax from rich.syntax import Syntax
from rich.text import Text from rich.text import Text
from textual.app import App from textual.app import App, ComposeResult
from textual.reactive import Reactive
from textual.widget import Widget from textual.widget import Widget
from textual.widgets import Static from textual.widgets import Static, DataTable
CODE = ''' CODE = '''
class Offset(NamedTuple): class Offset(NamedTuple):
@@ -46,11 +45,15 @@ class Offset(NamedTuple):
''' '''
lorem = Text.from_markup( lorem_short = """Lorem ipsum dolor sit amet, consectetur adipiscing elit. In velit liber a a a, volutpat nec hendrerit at, faucibus in odio. Aliquam hendrerit nibh sed quam volutpat maximus. Nullam suscipit convallis lorem quis sodales. In tristique lobortis ante et dictum. Ut at finibus ipsum."""
"""Lorem ipsum dolor sit amet, consectetur adipiscing elit. In velit libero, volutpat nec hendrerit at, faucibus in odio. Aliquam hendrerit nibh sed quam volutpat maximus. Nullam suscipit convallis lorem quis sodales. In tristique lobortis ante et dictum. Ut at finibus ipsum. In urna dolor, placerat et mi facilisis, congue sollicitudin massa. Phasellus felis turpis, cursus eu lectus et, porttitor malesuada augue. Sed feugiat volutpat velit, sollicitudin fringilla velit bibendum faucibus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In velit libero, volutpat nec hendrerit at, faucibus in odio. Aliquam hendrerit nibh sed quam volutpat maximus. Nullam suscipit convallis lorem quis sodales. In tristique lobortis ante et dictum. Ut at finibus ipsum. In urna dolor, placerat et mi facilisis, congue sollicitudin massa. Phasellus felis turpis, cursus eu lectus et, porttitor malesuada augue. Sed feugiat volutpat velit, sollicitudin fringilla velit bibendum faucibus. """ lorem = (
"""Lorem ipsum dolor sit amet, consectetur adipiscing elit. In velit libero, volutpat nec hendrerit at, faucibus in odio. Aliquam hendrerit nibh sed quam volutpat maximus. Nullam suscipit convallis lorem quis sodales. In tristique lobortis ante et dictum. Ut at finibus ipsum. In urna dolor, placerat et mi facilisis, congue sollicitudin massa. Phasellus felis turpis, cursus eu lectus et, porttitor malesuada augue. Sed feugiat volutpat velit, sollicitudin fringilla velit bibendum faucibus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In velit libero, volutpat nec hendrerit at, faucibus in odio. Aliquam hendrerit nibh sed quam volutpat maximus. Nullam suscipit convallis lorem quis sodales. In tristique lobortis ante et dictum. Ut at finibus ipsum. In urna dolor, placerat et mi facilisis, congue sollicitudin massa. Phasellus felis turpis, cursus eu lectus et, porttitor malesuada augue. Sed feugiat volutpat velit, sollicitudin fringilla velit bibendum faucibus. """ lorem_short
+ """ In urna dolor, placerat et mi facilisis, congue sollicitudin massa. Phasellus felis turpis, cursus eu lectus et, porttitor malesuada augue. Sed feugiat volutpat velit, sollicitudin fringilla velit bibendum faucibus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In velit libero, volutpat nec hendrerit at, faucibus in odio. Aliquam hendrerit nibh sed quam volutpat maximus. Nullam suscipit convallis lorem quis sodales. In tristique lobortis ante et dictum. Ut at finibus ipsum. In urna dolor, placerat et mi facilisis, congue sollicitudin massa. Phasellus felis turpis, cursus eu lectus et, porttitor malesuada augue. Sed feugiat volutpat velit, sollicitudin fringilla velit bibendum faucibus. """
) )
lorem_short_text = Text.from_markup(lorem_short)
lorem_long_text = Text.from_markup(lorem * 2)
class TweetHeader(Widget): class TweetHeader(Widget):
def render(self) -> RenderableType: def render(self) -> RenderableType:
@@ -58,8 +61,10 @@ class TweetHeader(Widget):
class TweetBody(Widget): class TweetBody(Widget):
short_lorem = Reactive(False)
def render(self) -> Text: def render(self) -> Text:
return lorem return lorem_short_text if self.short_lorem else lorem_long_text
class Tweet(Widget): class Tweet(Widget):
@@ -83,53 +88,64 @@ class Warning(Widget):
class Success(Widget): class Success(Widget):
def render(self) -> Text: def render(self) -> Text:
return Text("This is a success message", justify="center") return Text("This is a success message", justify="center")
class BasicApp(App): class BasicApp(App, css_path="basic.css"):
"""A basic app demonstrating CSS""" """A basic app demonstrating CSS"""
def on_load(self): def on_load(self):
"""Bind keys here.""" """Bind keys here."""
self.bind("tab", "toggle_class('#sidebar', '-active')") self.bind("s", "toggle_class('#sidebar', '-active')")
def on_mount(self): def compose(self) -> ComposeResult:
"""Build layout here.""" table = DataTable()
self.mount( self.scroll_to_target = Tweet(TweetBody())
header=Static(
Text.from_markup( yield Static(
"[b]This is a [u]Textual[/u] app, running in the terminal" Text.from_markup(
), "[b]This is a [u]Textual[/u] app, running in the terminal"
),
content=Widget(
Tweet(
TweetBody(),
# Widget(
# Widget(classes={"button"}),
# Widget(classes={"button"}),
# classes={"horizontal"},
# ),
),
Widget(
Static(Syntax(CODE, "python"), classes="code"),
classes="scrollable",
),
Error(),
Tweet(TweetBody()),
Warning(),
Tweet(TweetBody()),
Success(),
),
footer=Widget(),
sidebar=Widget(
Widget(classes="title"),
Widget(classes="user"),
OptionItem(),
OptionItem(),
OptionItem(),
Widget(classes="content"),
), ),
id="header",
) )
yield from (
Tweet(TweetBody()),
Widget(
Static(Syntax(CODE, "python"), classes="code"),
classes="scrollable",
),
table,
Error(),
Tweet(TweetBody(), classes="scrollbar-size-custom"),
Warning(),
Tweet(TweetBody(), classes="scroll-horizontal"),
Success(),
Tweet(TweetBody(), classes="scroll-horizontal"),
Tweet(TweetBody(), classes="scroll-horizontal"),
Tweet(TweetBody(), classes="scroll-horizontal"),
Tweet(TweetBody(), classes="scroll-horizontal"),
Tweet(TweetBody(), classes="scroll-horizontal"),
)
yield Widget(id="footer")
yield Widget(
Widget(classes="title"),
Widget(classes="user"),
OptionItem(),
OptionItem(),
OptionItem(),
Widget(classes="content"),
id="sidebar",
)
table.add_column("Foo", width=20)
table.add_column("Bar", width=20)
table.add_column("Baz", width=20)
table.add_column("Foo", width=20)
table.add_column("Bar", width=20)
table.add_column("Baz", width=20)
table.zebra_stripes = True
for n in range(100):
table.add_row(*[f"Cell ([b]{n}[/b], {col})" for col in range(6)])
async def on_key(self, event) -> None: async def on_key(self, event) -> None:
await self.dispatch_key(event) await self.dispatch_key(event)
@@ -137,17 +153,47 @@ class BasicApp(App):
def key_d(self): def key_d(self):
self.dark = not self.dark self.dark = not self.dark
async def key_q(self):
await self.shutdown()
def key_x(self): def key_x(self):
self.panic(self.tree) self.panic(self.tree)
def key_escape(self):
self.app.bell()
sandbox_folder = Path(__file__).parent def key_t(self):
app = BasicApp( # Pressing "t" toggles the content of the TweetBody widget, from a long "Lorem ipsum..." to a shorter one.
css_path=sandbox_folder / "basic.css", tweet_body = self.query("TweetBody").first()
watch_css=True, tweet_body.short_lorem = not tweet_body.short_lorem
log_path=sandbox_folder / "basic.log",
log_verbosity=0, def key_v(self):
) self.get_child(id="content").scroll_to_widget(self.scroll_to_target)
def key_space(self):
self.bell()
app = BasicApp()
if __name__ == "__main__": if __name__ == "__main__":
app.run() app.run()
# from textual.geometry import Region
# from textual.color import Color
# print(Region.intersection.cache_info())
# print(Region.overlaps.cache_info())
# print(Region.union.cache_info())
# print(Region.split_vertical.cache_info())
# print(Region.__contains__.cache_info())
# from textual.css.scalar import Scalar
# print(Scalar.resolve_dimension.cache_info())
# from rich.style import Style
# from rich.cells import cached_cell_len
# print(Style._add.cache_info())
# print(cached_cell_len.cache_info())

View File

@@ -27,7 +27,3 @@ def partition(
for value in iterable: for value in iterable:
appends[1 if pred(value) else 0](value) appends[1 if pred(value) else 0](value)
return result return result
if __name__ == "__main__":
print(partition((lambda n: bool(n % 2)), list(range(20))))