Commit graph jw-pkg/test
Author SHA1 Message Date
a1ae17c8cb
lib.Uri: Fix __assemble(): No '://' for relative paths
Assembling a scheme-bearing form always writes '://' after the scheme, even
if the input has no authority part. For a schemeless relative path such as
'../../local/path', .full then becomes 'file://../../local/path', which
re-parses with '..' as the host and '/../local/path' as the path, both
entirely broken.

Fix __assemble() to write a bare ':' instead of '://' when the input has no
host and a relative path, so the assembled form re-parses back to the same
relative path: full of '../../local/path' is now 'file:../../local/path'.
Absolute paths and forms with an authority are unchanged.

The assembled 'file:../../local/path' form is a valid URI under the RFC
3986 generic grammar (scheme with a rootless path), while RFC 8089's file
URI ABNF admits only an empty or an absolute path. Uri thus trades RFC 8089
conformance for RFC 3986 compatibility: a relative path survives the
full-and-reparse cycle unchanged.

Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-09-05 14:01:46 +02:00
1385b1a4ba lib.ExecApp: Add class
All checks were successful
CI / Packaging - Kali Linux (push) Successful in 11m50s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 4m14s
CI / Packaging test (push) Successful in 0s
ExecApp is a ready-made base class for applications that operate
through an ExecContext: it adds the --interactive, --verbose and
--target options, exposes interactive, verbose and exec_context
properties, and closes the exec context when the async context
manager exits.

The code for that has lived in jw.pkg.App code before, which now
inherits from ExecApp.

A fix along the way: __aexit__() closes the exec context and then chains
to super().__aexit__(), so App.close() runs when the async context
manager exits. Before the change, exiting the async context left the app
unclosed; close() ran only on the run() path. Add a unit test that
builds an ExecApp with a root command and asserts that close() runs on
context exit and that the exec options are registered.

The exec options are now registered before App's own options,
which moves them up in the rendered --help output. Update the
golden file of the help integration test to match.

Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
2026-08-22 17:31:57 +02:00
6b4bcdfaf8
lib.App: Add a root command slot
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 4m23s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 4m28s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 3m58s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 4m16s
CI / Packaging test (push) Successful in 0s
The application's top-level behavior is defined by overriding
App._add_arguments() and App._run(). The lightweight run-and-options
unit, Cmd, can already be mounted at any node of the command tree, but
the root is reserved for the application itself. An application that
wants to host a plain command at the top level therefore has to
subclass App and carry its full lifecycle implementation.

Add a root parameter to App.__init__(). When it is given a command
class, App instantiates it and uses it as the top level: the command's
options are registered on the top-level parser, it becomes the parent
of the top-level subcommands, and App._run() delegates the run to it.
The command's children are wired as the top-level subcommands, so the
same Cmd can now occupy the root node. When root is not given, the
previous auto-discovery behavior is preserved unchanged.

Keep the top-level subcommand heading as plain "Available subcommands"
whether it is hosted by the application or by a root command, while
nested command levels continue to qualify the heading with the parent
name. Add a unit test that mounts a root command hosting a child and
checks option registration, dispatch, setup and teardown, and
resolution of the application through the parent chain.

Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-17 12:53:05 +02:00
2eeaaf9681
lib.App: Make default log values overridable
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 4m0s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 4m11s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 3m40s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 3m59s
CI / Packaging test (push) Successful in 0s
The __init__() method reads default log configuration directly
from environment variables, making it impossible for subclasses to
change defaults.

Extract the defaults into _default_log_flags(), _default_log_level(),
_default_log_file(), and _default_show_backtrace() methods, then call
them from __init__(). Subclasses can now override these methods to
customize defaults without needing to override the entire __init__()
method.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-10 20:26:40 +02:00
41ca202142
cmds.projects.CmdBuild: Support --dep-flavours
CmdBuild supports the targets all, clean and pkg-*. It uses builtin
dependency flavours matching those targets to resolve build order. To
make it more flexible in general, and allow it to support more
targets, e.g. "check" and "test", this commit adds a --dep-flavours
option.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-24 13:35:27 +02:00
100d8f9abb
test/integration/jw-pkg/projects/cache: Add directory
Add tests for jw-pkg.py calls run during makefile caching. Broken
caching can compromise the build without causing it to fail entirely,
i.e. in non-obvious ways.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-24 13:23:52 +02:00
c8ffae57fc
test/integration/jw-pkg/projects: Add directory
Add a directory for integration tests of "jw-pkg projects".

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-24 13:22:37 +02:00
1062be24db
App: Remove hardcoded local/src from App and defs.mk
local/src is a janware-specific path, remove it from App and defs.mk.
It's still in pkg.sh as a safety measure. Will have to go, too, but
is kept in for now until further audit.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-24 13:20:18 +02:00
670472abf5
cmds.CmdPlatform: Fix typo "comamnds" -> "commands"
CmdPlatform's help message contains the string "comamnds", fix that.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-22 11:06:58 +02:00
8ba2b2434a
lib.ProjectConf: Remove empty line
yapf complains about a superfluous empty line, remove it.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-22 11:06:58 +02:00
7820fde4e6
test: Fix test.py duplicate module name error
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 4m17s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 4m9s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 4m19s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 3m59s
CI / Packaging test (push) Successful in 0s
Mypy scans both src/python/ and test/ under the same jw namespace,
and finds three test files named test.py. Without a package root at
the test/ level, mypy resolves all of them to the bare module name
test, and rejects them as duplicates.

Add __init__.py at test/ marks it as a package root, so each test.py
resolves to a unique full path, e.g.

  test.unit.python.jw.pkg.lib.Result.test

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.80.2
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-04 07:35:17 +02:00
8734b90f72
test: apply yapf formatting to test.py files
Yapf complains about spacing inconsistencies around assignment operators
in function calls, fix that.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.80.2
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-04 07:35:17 +02:00
ad9c5b581a
lib.ProjectConf: Clean up temp files
The _load() helper in test/unit/python/jw/pkg/lib/ProjectConf/test.py
uses tempfile.NamedTemporaryFile(..., delete=False) but never removes
the created files. Each test call leaked a .conf file in /tmp.

Track all created paths in a _tmpfiles list and call _cleanup() at the
end of the test to unlink them.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.80.2
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-04 07:35:06 +02:00
62803a4a1b
lib.Uri: Return 'file' scheme for local paths
The scheme property returns 'file://' for local paths instead of
'file', causing scheme_plus_authority to produce 'file://://' with a
triple slash.

Also fix the test to expect 'file' instead of 'file://'.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.80.2
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-04 07:21:43 +02:00
Jan Lindemann
2ca66e34ba
test: ProjectConf: Add unit tests
Add unit tests for the new ProjectConf module covering:

  - Basic string and list value retrieval (get_str(), get_str_or_none(),
    get_list(), get_list_or_none())
  - Quoted values with preserved spaces and comment delimiters
  - Inline comments outside quotes
  - Comma-separated lists with quoted commas
  - Line continuations
  - Multiple sections
  - Error cases: empty key, missing key/section, malformed sections,
    unfinished continuations, unclosed quotes
  - Error class is a subclass of ValueError

Also include a Makefile for running tests via `make test`.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL and pi.dev
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-06-30 12:46:42 +02:00
78f57c7547
jw.pkg.lib.Result: Add unit test
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 4m28s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 4m10s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 3m43s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 3m58s
CI / Packaging test (push) Successful in 0s
Add a unit test for the Result class covering:

  - stdout/stderr property access with various status values
  - None output handling and exception behavior
  - Encoding and strip_output property setters
  - cmd and wd setters
  - summary, summarize, and __repr__ behavior
  - matches_error pattern matching

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-06-25 20:57:22 +02:00
f4d40efc05
test: Move unit tests below jw/pkg
Move the unit test hierarchy to below test/unit/python/jw/pkg.
Nesting the subdirectories so deeply might be overly careful, but it
may as well be not - maybe in the future installable test packages
are going to be generated and need simple ways to install without
stepping onto each other's toes. If not, it's easier to cut two
directory components out than having to reorganize possibly
incoherent paths grown over multiple packages.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-06-25 20:57:05 +02:00
c94916d7de
jw.pkg.lib.Uri: Add unit test
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 3m48s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 4m29s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 4m7s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 4m14s
CI / Packaging test (push) Successful in 0s
The Uri class provides URL parsing and manipulation utilities used
throughout jw-pkg. Add a unit test covering URL parsing, credential
handling, path manipulation, and safe string formatting.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-06-25 19:08:02 +02:00
45f8e8cc89
test + python-tools.sh: Fix toplevel "make all" fallout
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 4m14s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 4m20s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 3m45s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 3m52s
CI / Packaging test (push) Successful in 0s
After a pipeline change, CI now runs "make all" in a repo's root,
which uncovers two problems:

1. The help integration test only succeeded as long CI didn't run
   "make all" before "make test". That way, the checked out
   repository lacked the generated __init__.py files needed for some
   modular subcommands to be fully loaded, and hence, the test should
   have failed. The entire machinery only worked because the
   subcommands in question are not not essential to building jw-pkg
   itself: "secrets" and "posix". So, this commit adapts the help
   integration test to the new reality.

2. Regarding python-tools.sh: Commit 55060486 satisfies yapf in some
   places of the source code, but in others not anylonger.  So patch
   python-tools.sh's newline handling again.

While not thematically similar, both fixes get baked into one commit
to satisfy the requirement that every single commit needs to pass
"make clean all check test" individually.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-06-25 18:28:36 +02:00
efc5bc1c60
test: Add subdirectory with integration test
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 3m38s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 3m39s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 4m21s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 4m32s
CI / Packaging test (push) Successful in 0s
Add a test/integration subdirectory as a location for integration
tests. The first tests that are added are unproblematic in that they
don't need superuser privileges to run:

  - help: Recursively check if jw-pkg.py's help messages are unchanged

  - packages ls: Check if the bash package exists and contains

      /usr/bin/bash
      /usr/bin/bashbug

Let's see how that fares in CI.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-06-25 14:40:53 +02:00