Skip to content

Commit

Permalink
pytest: add tests for pip and poetry installed virtual envs
Browse files Browse the repository at this point in the history
Also test checkout of a git tag on installation.
  • Loading branch information
endothermicdev committed Feb 1, 2024
1 parent 9fa297f commit ba7a37d
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pyln-client

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

plugin = Plugin()

__version__ = 'v1'


@plugin.init()
def init(options, configuration, plugin, **kwargs):
Expand All @@ -14,4 +16,10 @@ def testmethod(plugin):
return ("I live.")


@plugin.method("gettestplugversion")
def gettestplugversion(plugin):
"to test commit/tag checkout"
return __version__


plugin.run()
17 changes: 17 additions & 0 deletions tests/data/recklessrepo/lightningd/testplugpyproj/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[project]
dependencies = ["pyln-client"]

[tool.poetry]
name = "testplugpyproj"
version = "0.1.0"
description = "testing poetry installation of python plugins"
authors = ["Alex Myers <alex@endothermic.dev>"]

[tool.poetry.dependencies]
# Build dependencies belong here
python = "^3.8"
pyln-client = "^23.11"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3
from pyln.client import Plugin

plugin = Plugin()


@plugin.init()
def init(options, configuration, plugin, **kwargs):
plugin.log("testplug initialized")


@plugin.method("testmethod")
def testmethod(plugin):
return ("I live.")


plugin.run()
9 changes: 9 additions & 0 deletions tests/data/recklessrepo/rkls_api_lightningd_plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,14 @@
"git_url": "https://api.github.com/repos/lightningd/plugins/git/trees/testplugfail",
"download_url": null,
"type": "dir"
},
{
"name": "testplugpyproj",
"path": "testplugpyproj",
"url": "https://api.github.com/repos/lightningd/plugins/contents/webhook?ref=master",
"html_url": "https://github.com/lightningd/plugins/tree/master/testplugpyproj",
"git_url": "https://api.github.com/repos/lightningd/plugins/git/trees/testplugpyproj",
"download_url": null,
"type": "dir"
}
]
49 changes: 48 additions & 1 deletion tests/test_reckless.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,15 @@ def canned_github_server(directory):
repo_initialization = (f'cp -r {plugins_path}/* .;'
'git add --all;'
'git commit -m "initial commit - autogenerated by test_reckless.py";')
tag_and_update = ('git tag v1;'
"sed -i 's/v1/v2/g' testplugpass/testplugpass.py;"
'git add testplugpass/testplugpass.py;'
'git commit -m "update to v2";'
'git tag v2;')
subprocess.check_output([repo_initialization], env=my_env, shell=True,
cwd=repo_dir)
subprocess.check_output([tag_and_update], env=my_env,
shell=True, cwd=repo_dir)
del my_env['HOME']
del my_env['GIT_DIR']
del my_env['GIT_WORK_TREE']
Expand Down Expand Up @@ -189,6 +196,24 @@ def test_install(node_factory):
assert os.path.exists(plugin_path)


def test_poetry_install(node_factory):
"""test search, git clone, and installation to folder."""
n = get_reckless_node(node_factory)
r = reckless([f"--network={NETWORK}", "-v", "install", "testplugpyproj"], dir=n.lightning_dir)
assert r.returncode == 0
assert 'dependencies installed successfully' in r.stdout
assert 'plugin installed:' in r.stdout
assert 'testplugpyproj enabled' in r.stdout
check_stderr(r.stderr)
plugin_path = Path(n.lightning_dir) / 'reckless/testplugpyproj'
print(plugin_path)
assert os.path.exists(plugin_path)
n.start()
print(n.rpc.testmethod())
assert n.daemon.is_in_log(r'plugin-manager: started\([0-9].*\) /tmp/ltests-[a-z0-9].*/test_poetry_install_1/lightning-1/reckless/testplugpyproj/testplugpyproj.py')
assert n.rpc.testmethod() == 'I live.'


def test_local_dir_install(node_factory):
"""Test search and install from local directory source."""
n = get_reckless_node(node_factory)
Expand Down Expand Up @@ -232,4 +257,26 @@ def test_disable_enable(node_factory):
'active': True, 'dynamic': True}
time.sleep(1)
print(n.rpc.plugin_list()['plugins'])
assert(test_plugin in n.rpc.plugin_list()['plugins'])
assert test_plugin in n.rpc.plugin_list()['plugins']


def test_tag_install(node_factory):
"install a plugin from a specific commit hash or tag"
node = get_reckless_node(node_factory)
node.start()
r = reckless([f"--network={NETWORK}", "-v", "install", "testPlugPass"],
dir=node.lightning_dir)
assert r.returncode == 0
# should install v2 (latest) without specifying
version = node.rpc.gettestplugversion()
assert version == 'v2'
r = reckless([f"--network={NETWORK}", "-v", "uninstall", "testplugpass"],
dir=node.lightning_dir)
r = reckless([f"--network={NETWORK}", "-v", "install", "testplugpass@v1"],
dir=node.lightning_dir)
assert r.returncode == 0
# v1 should now be checked out.
version = node.rpc.gettestplugversion()
assert version == 'v1'
installed_path = Path(node.lightning_dir) / 'reckless/testplugpass'
assert installed_path.is_dir()

0 comments on commit ba7a37d

Please sign in to comment.