Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Development work flows
-
I am playing about with writing a Telegram Bot and Pythonista is working great, I love this app. I am just missing one thing now things are getting more complex: how do I run my code in a server on my machine for testing, I want to be able to input a value and get a response from the program without having to keep pressing the play button. I know some people on here are building some serious stuff and I can't believe they are doing this by running the script from start to finish each time?
Any help on some dev workflows to work round this would be really helpful, it's all I need to make Pythonista my main dev environment.
-
Whatevery you wrote, it's just Python code. It can be executed even if your code does contain shebang line
#!python3
, etc. Here's the list of potential issues you can have.Module is missing - set to None
Pythonista modules are not available outside of Pythonista. Like
console
for example.One way to handle modules that are not available is to wrap
import
withtry/except
and set the module toNone
if it's not avaiable. See log.py for example. Actually it should beexcept ImportError
instead of bareexcept
. And then just check if module was set or not.Module is missing - Mock
Another way is to use
unittest.mock
. If you do not want to check it againstNone
, you can do something like:try: import console except ImportError: console = unittest.mock.MagicMock()
Now you can call whatever from
console
,MagicMock
handles it and your code doesn't crash.mock
is useful not just for mocking non existing modules, but you can use it for other things like patching existing functions. You can even check if mocked method was called, check what arguments were passed, etc.Basically, if you have a module/function which handles communication with some server, you can patch this module / function to avoid real communication and to return whatever you need for tests.
You can learn more here.
Tests
Here's an example how to write tests. It's simple, I just started, but you can get a clue. Tests like these are runnable from within Pythonista (
Cmd U
in Black Mamba or via play button).Travis CI
And here's an example how to run style check & tests on Travis CI.
You'll probably see more issue than these mentioned ones, but it's a good starting point and it should solve major issues for you.