telenium icon indicating copy to clipboard operation
telenium copied to clipboard

TeleniumTestCase :: localy (desktop) run app :: FileNotFoundError

Open pdallair opened this issue 4 years ago • 0 comments

Description

When using TeleniumTestCase's default cmd_entrypoint value ([main.py]) we run into a problem at the following method call.

@classmethod
    def start_desktop_process(cls, cmd, env):
        cwd = os.path.dirname(cls.cmd_entrypoint[0])
        cls.process = subprocess.Popen(cmd, env=env, cwd=cwd)

Obviously, os.path.dirname returns an empty string here. As much as the user can overwrite the cmd_entrypoint value to include an absolute or relative path, the default value should work under the right circumstances. The fix is very simple, wrap the cls.cmd_entrypoint[0] argument with a os.path.abspath call — which is a pretty common practice actually. This will convert any valid path provided (including no path information at all if the file is in the cwd) into the full absolute path to the existing file.

PR on the way soon.

Various logs and file contents

main.py

import platform

import kivy

from kivy.app import App
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label


class FretboardDojo(App):
    def build(self):
        root_layout = AnchorLayout(anchor_x="center", anchor_y="center")
        widget_layout = BoxLayout(orientation="vertical", size_hint=(None, None))
        widget_layout.add_widget(Label(text='Test App'))
        widget_layout.add_widget(Label(text=f'Python {platform.python_version()}'))
        widget_layout.add_widget(Label(text=f'Kivy {kivy.__version__}'))
        root_layout.add_widget(widget_layout)
        return root_layout


if __name__ == "__main__":
    FretboardDojo().run()

buildozer.spec

[app]
title = Test App
package.name = testapp
package.domain = org.kivy
source.dir = .
source.include_exts = py,png,jpg,kv,atlas
version = 0.1
requirements = python3,kivy,zipp,more-itertools,pytz,jaraco.functools,importlib-resources,tempora,six,jaraco.text,jaraco.classes,zc.lockfile,portend,MarkupSafe,jaraco.collections,cheroot,ws4py,Werkzeug,Mako,json-rpc,CherryPy,telenium
orientation = portrait
fullscreen = 0

android.permissions = INTERNET,ACCESS_NETWORK_STATE
android.arch = armeabi-v7a

[buildozer]
log_level = 2
warn_on_root = 1

test.py

from telenium.tests import TeleniumTestCase


class TestFretboardDojo(TeleniumTestCase):
    def test_startup_screen(self):
        self.assertExists("//Label[@text~=\"Test App\"]", timeout=2)

PyCharm Console Output

/home/pdallair/anaconda3/envs/telenium/bin/python /snap/pycharm-community/261/plugins/python-ce/helpers/pycharm/_jb_unittest_runner.py --path /home/pdallair/dev/PycharmProjects/Telenium/TestApp/test.py
Testing started at 8:34 p.m. ...
Launching unittests with arguments python -m unittest /home/pdallair/dev/PycharmProjects/Telenium/TestApp/test.py in /home/pdallair/dev/PycharmProjects/Telenium/TestApp

> app_quit: ()

Failure
Traceback (most recent call last):
  File "/home/pdallair/anaconda3/envs/telenium/lib/python3.9/unittest/suite.py", line 166, in _handleClassSetUp
    setUpClass()
  File "/home/pdallair/dev/PycharmProjects/Telenium/telenium/tests.py", line 121, in setUpClass
    cls.start_process()
  File "/home/pdallair/dev/PycharmProjects/Telenium/telenium/tests.py", line 66, in start_process
    cls.start_desktop_process(cmd=cmd, env=env)
  File "/home/pdallair/dev/PycharmProjects/Telenium/telenium/tests.py", line 87, in start_desktop_process
    cls.process = subprocess.Popen(cmd, env=env, cwd=cwd)
  File "/home/pdallair/anaconda3/envs/telenium/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/pdallair/anaconda3/envs/telenium/lib/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: ''

pdallair avatar Dec 12 '21 01:12 pdallair