Skip to content

Commit

Permalink
Added tests and pytest configs, updated app init classes 🧪
Browse files Browse the repository at this point in the history
  • Loading branch information
Koen van Eijk committed Sep 21, 2020
1 parent 1f4b7b0 commit fff408c
Show file tree
Hide file tree
Showing 13 changed files with 249 additions and 201 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ migrated
.vscode
*.whl
.coverage
bin
bin
htmlcov
cov.xml
32 changes: 21 additions & 11 deletions automagica/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import os

import click
import tkinter as tk

from automagica.config import Config, _
from automagica.gui.apps import (
AutomagicaTk,
BotApp,
FlowApp,
LabApp,
Expand Down Expand Up @@ -39,8 +41,9 @@ def bot():
"""
'automagica bot' launches the Automagica Bot
"""
app = BotApp()
app.run()
root = AutomagicaTk()
_ = BotApp(root)
root.mainloop()


@cli.command("wand", help=_("Automagica Wand"))
Expand All @@ -57,8 +60,9 @@ def on_finish(automagica_id):
print(f"Automagica ID: {automagica_id}")
os._exit(0)

app = WandApp(delay=delay, on_finish=on_finish)
app.run()
root = AutomagicaTk()
_ = WandApp(root, delay=delay, on_finish=on_finish)
root.mainloop()


@cli.group(help=_("Automagica Flow"))
Expand All @@ -74,8 +78,9 @@ def flow_new():
"""
`automagica flow new` creates a new Automagica Flow
"""
app = FlowApp()
app.run()
root = AutomagicaTk()
_ = FlowApp(root)
root.mainloop()


@flow.command("edit", help=_("Edit Flow"))
Expand All @@ -84,8 +89,9 @@ def flow_edit(file_path):
"""
`automagica flow edit <filename>` opens an existing Automagica Flow for editing
"""
app = FlowApp(file_path=file_path)
app.run()
root = AutomagicaTk()
_ = FlowApp(root, file_path=file_path)
root.mainloop()


@flow.command("run", help=_("Run Flow"))
Expand All @@ -104,15 +110,18 @@ def flow_run(filename, headless, step_by_step):
"""
`automagica flow run <filename>` opens an existing Automagica Flow and executes it
"""
root = AutomagicaTk()

# Run FLow
app = FlowApp(
root,
file_path=filename,
run=True,
headless=headless,
step_by_step=step_by_step,
)

app.run()
root.mainloop()


@cli.group(help=_("Automagica Lab"))
Expand Down Expand Up @@ -156,8 +165,9 @@ def trace():

@trace.command("record", help=_("Record a new Trace"))
def trace_record():
app = TraceApp()
app.run()
root = AutomagicaTk()
_ = TraceApp(root)
root.mainloop()


@cli.group(help=_("Automagica Script"))
Expand Down
42 changes: 12 additions & 30 deletions automagica/gui/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@
)


class App(tk.Tk):
def __init__(self, *args, config=None, **kwargs):
class AutomagicaTk(tk.Tk):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

# Hide Tkinter root window
self.withdraw()


class App(tk.Toplevel):
def __init__(self, *args, config=None, **kwargs):
super().__init__(*args, **kwargs)

# Hide this parent window
self.withdraw()

# Load config
self.config = config

Expand All @@ -44,21 +52,6 @@ def __init__(self, *args, config=None, **kwargs):
if platform.system() == "Windows":
self._windows_set_dpi_awareness()

# Set Automagica icon
icon_path = os.path.join(
os.path.abspath(__file__).replace(
os.path.basename(os.path.realpath(__file__)), ""
),
"icons",
"automagica.ico",
)
self.tk.call(
"wm",
"iconphoto",
self._w,
ImageTk.PhotoImage(Image.open(icon_path)),
)

ICONS.generate_icons()

def _windows_set_dpi_awareness(self):
Expand All @@ -76,8 +69,8 @@ def _windows_set_dpi_awareness(self):
logging.exception("Could not set DPI awareness on Windows.")

def report_callback_exception(self, exception, value, traceback):
"""
Override default tkinter method to log errors
"""
Override default tkinter method to log errors
"""
self.config.logger.exception(exception)

Expand Down Expand Up @@ -135,9 +128,6 @@ def __init__(
else:
FlowDesignerWindow(self, bot=self.bot)

# Run sounds better, right?
self.run = self.mainloop

def close_app(self, exit_code=0):
self.bot.stop()
os._exit(exit_code)
Expand All @@ -160,7 +150,6 @@ def run(self):
"""Run Bot app"""
self.runner_thread.start()
self.alive_thread.start()
self.mainloop()

def run_notebook(self, file_path, cwd):
"""Run a notebook"""
Expand Down Expand Up @@ -401,16 +390,12 @@ def _runner_thread(self, interval=10, retry_interval=5 * 60):
class WandApp(App):
def __init__(self, *args, delay=0, on_finish=None, **kwargs):
super().__init__(*args, **kwargs)
self.withdraw()

# Open the main window
self.wand_window = WandWindow(
self, standalone=True, delay=delay, on_finish=on_finish
)

# Run sounds better :-)
self.run = self.mainloop


class TraceApp(App):
def __init__(self, *args, **kwargs):
Expand All @@ -420,9 +405,6 @@ def __init__(self, *args, **kwargs):

self.capture = Capture()

# Run sounds better :)
self.run = self.mainloop


class LabApp:
def __init__(self, config=None):
Expand Down
11 changes: 6 additions & 5 deletions automagica/gui/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ def add_node(self, node_type):
"""
node = self.flow.add_node(node_type)
self.flow_frame.add_node_graph(node)
return node


class FlowPlayerWindow(tk.Toplevel):
Expand Down Expand Up @@ -699,7 +700,7 @@ def create_validation_errors_frame(self):

class NotificationWindow(tk.Toplevel):
"""
The notification window is a small notification window in
The notification window is a small notification window in
the corner of the screen, which fades out when disappearing.
"""

Expand Down Expand Up @@ -946,7 +947,7 @@ def settings_clicked(self):
"""
When the user clicks 'settings'
"""
ConfigWindow(self)
return ConfigWindow(self)

def mouse_double_click(self, event):
"""
Expand Down Expand Up @@ -1292,8 +1293,8 @@ def create_target_frame(self):
def _resize_to_fit(self, image, fit_w, fit_h):
"""
Resize the image to fit
TODO: this should probably be a utility
TODO: this should probably be a utility
function rather than a window-specific method
"""
w, h = image.size
Expand Down Expand Up @@ -1616,7 +1617,7 @@ def layout(self):
self.buttons_frame.pack()

def add_button_clicked(self):
_ = KeybindWindow(self)
return KeybindWindow(self)

def remove_button_clicked(self):
i = self.keybinds_listbox.curselection()[0]
Expand Down
16 changes: 13 additions & 3 deletions docs/source/getting_started.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Getting started

## Installing on Windows
Download Automagica and get started automating within 5 minutes through our website [automagica.com](https://www.automagica.com).
Download Automagica and get started automating within 5 minutes through our website [automagica.com](https://www.automagica.com).
Our one-click installer for Windows in combination with Automagica Flow is by far the easiest way to get started automating.

By signing up for the [Automagica Portal](https://www.portal.automagica.com), you also gain access to our specialized OCR-service and our Automagica Wand back-end, which features computer vision powered by machine learning for recognizing UI elements.
Expand Down Expand Up @@ -31,10 +31,20 @@ You can install Automagica by running the following commands:
```
sudo apt-get install python3-devel chromium -y
sudo pip3 install automagica -U
## Installation on Linux
Interactive one-click examples with documentation can be found on [portal.automagica.com](https://portal.automagica.com)
```

### Additional requirements for Automagica Flow
Automagica Flow is built in tkinter, and thus requires some additional packages under Linux:

```bash
sudo apt-get install python3 \
python3-tk \
python3-pip \
python3-dev \
chromium -y
```


## Your first automation

There are multiple ways to automate tasks with Automagica. Down below a short overview of the different editors and what type of user it is designed for.
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ line-length = 79
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

[tool.pytest.ini_options]
minversion = "6.0"
addopts = "--cov=automagica --cov-report xml:cov.xml"
testpaths = ["tests"]
markers = ["smoke: signal big problems"]
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pytest

from automagica.gui.apps import AutomagicaTk

# This is required to launch a single instance of the Tkinter interpreter
# as launching the Tkinter interpreter multiple times from within the same
# Python process causes problems.
pytest.automagica_tk = AutomagicaTk()
4 changes: 0 additions & 4 deletions tests/pytest.ini

This file was deleted.

Loading

0 comments on commit fff408c

Please sign in to comment.