bandsaunter/tests/test_licence.py
The Dust Council 2665a17a22 Cache what has been looked up, make it browsable, and say where this lives
Four things asked for in turn, landing together because they run through the
same files.

THE MAPS.  The tiles were already cached and always had been -- a second
evening on the same view was measured at nought network requests -- but the
work done on them was not.  Every window open decoded forty PNGs and resampled
a megapixel and a half into this program's own projection, for an answer that
cannot have changed, because a coastline does not move.  The finished map is
kept beside the tiles now: 0.61 seconds become 0.01, byte for byte identical,
two hundred kilobytes a view.  Both windows and both kinds of still picture get
it, all four reaching the ground through one function.  A map with squares
missing is deliberately not kept, since caching a hole would keep it for a
month and the point of calling a partial map provisional is that it is asked
for again.  And because this adds a disk consumer, the whole cache is now
pruned to four hundred megabytes, least recently *used* first: a tile fetched a
year ago and looked at last night is the receiver's own neighbourhood, and
discarding that to keep last week's holiday is the wrong way round.

THE LOOKUPS.  APRS and FT8 now ask who each station is licensed to.  Every
other mode that hears a callsign already did -- speech transcripts, Morse
idents, the recording browser -- and all five resolve through one file, so a
callsign heard on two bands is asked about once.  The rules for finding the
licensed callsign inside a heard one are now in one place rather than per band,
because getting them wrong is silent: a register asked about W1AW-9 returns
nothing, which looks exactly like a station that is not licensed.  An SSID, a
rover suffix, a guest prefix, a digipeater alias and an unspelled hash all come
off or are refused.

The bug worth recording is that the first cut of this did the lookups and threw
them away.  The book has to be told to save and was not, so every evening would
have asked the register about the same net again -- which is the one thing
caching them was for, and is invisible from inside a single run because the
answers are all in memory while it lasts.  Caught by looking at the file on
disk rather than at the display.  There is a test for each side of it now, and a
register of which modules resolve callsigns at all, which fails when a new one
starts so that somebody has to decide whether it should.

THE REGISTER.  c in saunterbrowse opens everything ever looked up: sixty-odd
callsigns and sixteen hundred aircraft here, every field of each in two columns
because a licence has a dozen and a screen is wider than it is tall.  tab
switches, / searches every field rather than the name -- the question is
usually "who was in Arizona" rather than "which callsign" -- and g opens the
place in a browser.  Only the coordinates go into that link: a map does not
need to be told whose licence it is looking at, and the link is the one part of
this that leaves the machine.  A headless box, which is the normal case for a
receiver, gets the coordinates printed instead.  Callsigns no register could
place are kept rather than dropped, because "asked about, and in no register
reachable from here" is a fact about a station.

THE FRONT OF IT.  A title screen for each program: five rows of blocks cut by
hand, a figlet dependency to draw eleven letters being the largest thing that
would then be in the requirements, coloured blue to red across the width, which
is the ramp every waterfall here already uses because it is what a spectrum
looks like.  The interesting part is where it does not appear -- everything
here can be piped into something else and a banner in the middle of that is
corruption rather than decoration, so anything that is not a terminal gets
nothing, --help is untouched because it is drawn after parsing, --no-splash
turns it off for a run and BANDSAUNTER_NO_SPLASH=1 for good.

And the address.  INSTALL.md said "git clone <the repository>" for a long time:
a placeholder in the first command anybody types, unnoticed because nothing
reads install instructions except somebody installing, who then cannot.  It is
filled in, along with the readme, the metadata, both manuals and the Homepage
field of all three packages.  The tile server's User-Agent pointed at a topic
listing on somebody else's site for want of an address of its own; the usage
policy of that service asks for one naming the application and giving somewhere
to look it up, so an operator with a question about the traffic has somebody to
ask, and now it gives the real one.  Seven tests so the placeholder cannot come
back, verified by putting it back and watching two of them fail.

One thing forced by all this: the keys page in saunterbrowse was exactly as
tall as an eighty-by-twenty-four terminal, so the register entry pushed "q
quit" off the bottom.  A test caught it.  Home and End have merged into the
Page Up line, which were always the same thought.

THE WINDOWS.  They open maximised now, this being a map and the thing anybody
wants more of being map; f goes to true full screen and back, and is written
along the top of the screen because a window with no frame is one somebody has
to know a key to get out of.  Maximised rather than frameless by default,
because the title bar is where the band and the frequency are written.

And a map made bigger now gets a sharper map, which it did not.  The window
only ever re-examined the ground when the view left the box that had been
fetched, so a window opened at its default size and taken to the whole screen
kept the map it started with until an aircraft wandered far enough to move it
-- on a quiet band, a long time to look at a blurred coastline.  Measured
before it was believed: 1100 to 1920 asked for nothing and stretched a
1364-pixel map across 1920, then across 3840.  It now compares map pixels per
degree in hand against what the view wants, and asks when it is being blown up
by more than fifteen per cent.

That comparison has to be per degree rather than pixel against pixel, which a
surviving mutation was what established: the fetched box is a quarter wider
than the view, so a map with exactly as many pixels as the window is wide has
only four fifths of them on the screen.  The two ways of measuring agree
everywhere except a narrow band, and the realistic case sits inside it.  There
is a test pinning that case now.  Asking is safe at any size, because the
request is keyed on the window's dimensions: once answered, nothing more is
asked, which is what stops a window larger than the tile budget can cover from
asking all evening.

The braille, while this was open.  The banners were blocks in capitals; they
are braille in mixed case, two dots wide and four tall to a character, which is
eight times the detail and is what makes room for two heights of letter at
once -- a five-row block font has no second height to spend, so the name came
out shouted.  Two attempts failed first: thin one-dot strokes came out as
confetti, because braille dots render as dots and a one-dot stroke reads as a
dotted line rather than a line.  What worked was cutting the font small, at cap
height seven where there is only one way to draw each letter, and doubling it.
Coloured deep blue through cyan to a cool white, which is deliberately not the
waterfall ramp the rest of the program draws in: that one has to run to red
because it stands in for a spectrum, and a title screen stands in for nothing.

One hundred and four new tests.  Full suite 2892 passed.  Built as
2026-09-24_01.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016PsWPTweCT6pwxKngvVxcg
2026-09-24 00:36:18 -07:00

321 lines
13 KiB
Python

"""The licence, and the instructions for installing under it.
Both are files a person reads rather than code that runs, which is exactly why
they are worth a test: nothing else notices when a licence file goes missing
from a package, when the version notice stops naming the terms, or when the
install instructions describe a command that no longer exists.
"""
import re
import subprocess
import sys
from pathlib import Path
import pytest
import bandsaunter
ROOT = Path(__file__).resolve().parent.parent
LICENCE = ROOT / "LICENSE"
INSTALL = ROOT / "INSTALL.md"
README = ROOT / "README.md"
# ---------------------------------------------------------------------------
# The licence itself
# ---------------------------------------------------------------------------
def test_the_licence_is_there_and_is_the_gnu_gpl():
assert LICENCE.is_file(), "no LICENSE file"
text = LICENCE.read_text()
assert "GNU GENERAL PUBLIC LICENSE" in text
assert "Version 3, 29 June 2007" in text
def test_the_licence_is_the_whole_of_it():
"""A truncated licence is not a licence. The GPL ends with the notice it
tells you to attach to a program, so if that is present, so is the rest."""
text = LICENCE.read_text()
assert "TERMS AND CONDITIONS" in text
assert "How to Apply These Terms to Your New Programs" in text
assert len(text.splitlines()) > 600
def test_the_packaging_metadata_says_the_same_licence():
body = (ROOT / "pyproject.toml").read_text()
assert 'license = {text = "GPL-3.0-or-later"}' in body
assert "GNU General Public License v3 or later" in body
def test_the_readme_says_which_licence_and_points_at_the_file():
body = README.read_text()
assert "GNU General Public License" in body
assert "[LICENSE](LICENSE)" in body
# ---------------------------------------------------------------------------
# What the programs say for themselves
# ---------------------------------------------------------------------------
@pytest.mark.parametrize("program", ["bandsaunter", "saunterbrowse"])
def test_the_version_notice_names_the_version_and_the_terms(program):
notice = bandsaunter.version_notice(program)
lines = notice.splitlines()
assert lines[0] == f"{program} {bandsaunter.__version__}"
assert "Copyright (C)" in notice
assert "GNU GPL version 3 or later" in notice
assert "NO WARRANTY" in notice
def test_the_command_prints_it():
out = subprocess.run([sys.executable, "-m", "bandsaunter", "--version"],
capture_output=True, text=True, timeout=60)
assert bandsaunter.__version__ in out.stdout
assert "GPLv3+" in out.stdout
# Four lines under the version, not reflowed into a paragraph by argparse.
assert len(out.stdout.strip().splitlines()) == 5
# ---------------------------------------------------------------------------
# The manuals
# ---------------------------------------------------------------------------
@pytest.mark.parametrize("page", ["bandsaunter.1", "saunterbrowse.1"])
def test_both_manuals_have_a_copying_section(page):
body = (ROOT / "packaging" / page).read_text()
assert ".SH COPYING" in body
assert "General\nPublic License" in body or "General Public License" in body
# ---------------------------------------------------------------------------
# The Debian package carries the licence where policy says it must
# ---------------------------------------------------------------------------
def test_the_package_ships_the_licence_at_the_path_policy_requires():
script = (ROOT / "packaging" / "build-deb.sh").read_text()
assert "usr/share/doc/bandsaunter/copyright" in script
assert '"$here/LICENSE"' in script
def test_the_package_ships_the_install_instructions_too():
assert 'INSTALL.md' in (ROOT / "packaging" / "build-deb.sh").read_text()
# ---------------------------------------------------------------------------
# The install instructions
# ---------------------------------------------------------------------------
def test_the_install_file_exists_and_is_pointed_at_from_the_readme():
assert INSTALL.is_file(), "no INSTALL.md"
assert "[INSTALL.md](INSTALL.md)" in README.read_text()
def test_the_install_file_covers_both_ways_of_installing():
body = INSTALL.read_text()
assert "./packaging/build-deb.sh" in body
assert "python3 -m venv" in body
assert "pip install ." in body
def test_it_warns_about_the_thing_every_debian_user_hits_first():
"""pip refuses to install outside a virtual environment on Debian and
Fedora. Someone who has not met PEP 668 reads that error as a broken
program."""
body = INSTALL.read_text()
assert "externally-managed-environment" in body
assert "PEP 668" in body
def test_it_lists_the_optional_dependencies_and_what_each_one_buys():
body = INSTALL.read_text()
for optional in ("espeak-ng", "ffmpeg", "faster-whisper", "vosk",
"rtl-sdr", "pyqt6", "openai-whisper", "pocketsphinx"):
assert optional in body, optional
# What each one buys, and what is lost without it: the two columns are
# the point of the table, not the list of names.
assert "Gives you" in body and "Without it" in body
assert "Optional." in body
def test_it_lists_the_required_dependencies_and_who_needs_them():
"""Somebody installing from scratch has to be told the whole of it,
including the one piece pip cannot bring."""
body = INSTALL.read_text()
for required in ("python3-numpy", "python3-scipy", "python3-rich",
"python3-yaml", "librtlsdr0"):
assert required in body, required
assert "Fedora" in body and "Arch" in body
def test_it_says_which_dependency_pip_cannot_install():
"""librtlsdr is a C library, so no virtual environment brings it and it
is the one thing that has to come from the distribution by hand."""
body = INSTALL.read_text()
assert "librtlsdr" in body
assert "pip` cannot install it" in body or "cannot come from pip" in body
assert "dnf install rtl-sdr" in body
assert "pacman -S rtl-sdr" in body
assert "brew install librtlsdr" in body
def test_it_says_what_reaches_a_network_and_where_it_is_cached():
"""Nothing is fetched behind anybody's back, and somebody installing
this on a metered or air-gapped machine has to be able to see that."""
body = INSTALL.read_text()
for source in ("api.adsbdb.com", "hexdb.io", "tile.openstreetmap.org",
"overpass-api.de"):
assert source in body, source
assert "~/.cache/bandsaunter/tiles" in body
def test_it_says_how_to_install_the_recogniser_and_the_model():
"""The one part with a real download in it, and the part that has to be
put in the same environment bandsaunter runs from."""
body = INSTALL.read_text()
assert "pip install faster-whisper" in body
assert "--user --break-system-packages" in body # the ~/.local layout
assert "bandsaunter transcribe --engines" in body # how to check it took
assert "Systran/faster-whisper-base.en" in body # what gets downloaded
assert "~/.cache/huggingface" in body # and where it lands
assert "WhisperModel('base.en'" in body # fetching it on purpose
def test_the_model_the_instructions_name_is_the_one_the_program_asks_for():
"""The instructions download base.en because that is the default; if the
default moves, they are downloading the wrong thing."""
from bandsaunter.config import ScanConfig
assert ScanConfig().transcribe_model in INSTALL.read_text()
def test_it_names_the_ways_a_model_can_be_supplied_without_a_network():
body = INSTALL.read_text()
assert "BANDSAUNTER_MODEL_DIR" in body
assert "/usr/share/bandsaunter/models" in body
assert "build-repo.sh" in body
def test_it_says_where_the_engine_output_switch_is():
"""A silent minute on the first transcription reads as a hang."""
assert "BANDSAUNTER_ENGINE_OUTPUT=1" in INSTALL.read_text()
def test_the_environment_variables_it_names_are_the_ones_the_code_reads():
from bandsaunter import transcribe as tr
body = INSTALL.read_text()
for variable in ("BANDSAUNTER_MODEL_DIR", "BANDSAUNTER_ENGINE_OUTPUT"):
assert variable in body
assert str(tr.MODEL_DIR) in body or "BANDSAUNTER_MODEL_DIR" in body
def test_the_settings_it_tells_you_to_change_exist():
from bandsaunter.config import ScanConfig
fields = set(ScanConfig().__dict__)
told = set(re.findall(r"bandsaunter config ([a-z_]+)=", INSTALL.read_text()))
assert told, "the instructions change no settings at all"
assert told <= fields, told - fields
def test_it_says_what_to_do_when_the_dongle_is_not_found():
body = INSTALL.read_text()
assert "dvb_usb_rtl28xxu" in body
assert "librtlsdr" in body
def test_every_bandsaunter_command_it_tells_you_to_run_exists():
"""An instruction to run a command that was renamed is worse than none."""
from bandsaunter.cli import build_parser
known = set()
for action in build_parser()._subparsers._group_actions:
known.update(action.choices)
told = set(re.findall(r"^\s*(?:\$ )?bandsaunter ([a-z]+)",
INSTALL.read_text(), re.MULTILINE))
assert told, "the instructions run no commands at all"
assert told <= known | {"--version"}, told - known
def test_the_flags_it_tells_you_to_use_are_real():
from bandsaunter.cli import build_parser
parser = build_parser()
for line in ("scan -b 2m --simulate", "adsb --simulate --seconds 30",
"devices --test", "transcribe --engines"):
parser.parse_args(line.split()) # raises SystemExit if not
# ---------------------------------------------------------------------------
# Where it lives
# ---------------------------------------------------------------------------
REPOSITORY = "https://frostwarning.com/git/dustcouncil/bandsaunter"
def test_the_install_instructions_say_where_to_clone_from():
"""This said "git clone <the repository>" for a long time.
Nothing noticed, because nothing reads the install instructions except
somebody installing -- who then cannot. A placeholder in the one
command a new person types first is the worst place for one, so it is
checked here rather than hoped about.
"""
body = INSTALL.read_text()
clones = re.findall(r"^git clone\s+(\S+)", body, re.MULTILINE)
assert clones, "the install instructions do not say how to get the source"
for where in clones:
assert where.startswith(("http://", "https://", "git@", "ssh://")), \
f"not a repository anybody can clone: {where!r}"
assert "<" not in where and ">" not in where, \
f"still a placeholder: {where!r}"
@pytest.mark.parametrize("path", ["INSTALL.md", "README.md",
"pyproject.toml"])
def test_the_files_a_new_person_reads_have_no_placeholders_left(path):
"""Angle brackets around a word are how a placeholder is written, and
every one of them is a sentence somebody cannot act on."""
body = (ROOT / path).read_text()
# Inside a fenced block a placeholder is an instruction to substitute;
# outside one it is prose. Both are checked, and both are wrong when the
# thing to substitute is the repository.
for bad in ("<the repository>", "<repository>", "<repo>", "<URL>",
"<url>"):
assert bad not in body, f"{path} still says {bad}"
def test_the_packaging_metadata_names_the_repository():
import tomllib
body = tomllib.load(open(ROOT / "pyproject.toml", "rb"))
urls = body["project"].get("urls") or {}
assert urls, "pyproject names no homepage at all"
assert any(REPOSITORY in v for v in urls.values())
@pytest.mark.parametrize("page", ["bandsaunter.1", "saunterbrowse.1"])
def test_both_manuals_say_where_the_source_is(page):
body = (ROOT / "packaging" / page).read_text()
assert REPOSITORY in body, f"{page} does not say where to find the source"
def test_the_built_package_says_where_it_came_from():
"""Debian policy asks for a Homepage field, and an installed package
that cannot say where it came from is one nobody can update."""
for script in ("build-deb.sh", "build-repo.sh"):
body = (ROOT / "packaging" / script).read_text()
assert f"Homepage: {REPOSITORY}" in body, script
assert "Maintainer: bandsaunter" not in body, \
f"{script} still names the package as its own maintainer"
def test_the_tile_server_is_told_where_to_look_this_program_up():
"""Not decoration: the usage policy of the service the default tiles
come from asks for a User-Agent that identifies the application and
gives somewhere to look it up, so that an operator with a question
about the traffic has somebody to ask."""
from bandsaunter.basemap import USER_AGENT
assert "bandsaunter/" in USER_AGENT
assert REPOSITORY in USER_AGENT
assert bandsaunter.__version__ in USER_AGENT