mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-15 20:09:18 +01:00
pytest: add tests for pip and poetry installed virtual envs
Also test checkout of a git tag on installation.
This commit is contained in:
parent
3879d7b9bd
commit
140e33b13a
6 changed files with 118 additions and 1 deletions
|
@ -0,0 +1,2 @@
|
|||
pyln-client
|
||||
|
|
@ -3,6 +3,8 @@ from pyln.client import Plugin
|
|||
|
||||
plugin = Plugin()
|
||||
|
||||
__version__ = 'v1'
|
||||
|
||||
|
||||
@plugin.init()
|
||||
def init(options, configuration, plugin, **kwargs):
|
||||
|
@ -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()
|
||||
|
|
|
@ -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"
|
17
tests/data/recklessrepo/lightningd/testplugpyproj/testplugpyproj.py
Executable file
17
tests/data/recklessrepo/lightningd/testplugpyproj/testplugpyproj.py
Executable file
|
@ -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()
|
|
@ -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"
|
||||
}
|
||||
]
|
||||
|
|
|
@ -61,8 +61,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']
|
||||
|
@ -191,6 +198,25 @@ def test_install(node_factory):
|
|||
assert os.path.exists(plugin_path)
|
||||
|
||||
|
||||
@unittest.skipIf(VALGRIND, "virtual environment triggers memleak detection")
|
||||
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.'
|
||||
|
||||
|
||||
@unittest.skipIf(VALGRIND, "virtual environment triggers memleak detection")
|
||||
def test_local_dir_install(node_factory):
|
||||
"""Test search and install from local directory source."""
|
||||
|
@ -236,4 +262,42 @@ 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']
|
||||
|
||||
|
||||
@unittest.skipIf(VALGRIND, "virtual environment triggers memleak detection")
|
||||
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
|
||||
metadata = node.lightning_dir / "reckless/testplugpass/.metadata"
|
||||
with open(metadata, "r") as md:
|
||||
header = ''
|
||||
for line in md.readlines():
|
||||
line = line.strip()
|
||||
if header == 'requested commit':
|
||||
assert line == 'None'
|
||||
header = line
|
||||
# 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()
|
||||
with open(metadata, "r") as md:
|
||||
header = ''
|
||||
for line in md.readlines():
|
||||
line = line.strip()
|
||||
if header == 'requested commit':
|
||||
assert line == 'v1'
|
||||
header = line
|
||||
|
|
Loading…
Add table
Reference in a new issue