Files
FinalToken/tools/test_publish.py
T
Florian Schmidt b0c203c8f6 tools: preserve license bytes in packaging checks
Validate source, copied and archived notices byte-for-byte for both LF and CRLF checkouts. Keep platform newline conversion from causing false release-test failures.

Refs #19
2026-11-15 11:15:23 +01:00

56 lines
2.7 KiB
Python

"""Check release assembly and manifest versions without invoking NativeAOT."""
import contextlib
import io
import json
from pathlib import Path
import tempfile
import unittest
from unittest.mock import patch
import xml.etree.ElementTree as ET
import zipfile
import publish
class PublishTests(unittest.TestCase):
def test_published_manifest_uses_shared_version(self):
self.check_package()
def test_license_copy_preserves_lf_and_crlf_bytes(self):
for newline in (b'\n', b'\r\n'):
with self.subTest(newline=newline), tempfile.TemporaryDirectory(prefix='finaltoken-license-') as temporary:
root = Path(temporary)
(root / 'Directory.Build.props').write_text('<Project><Version>1.2.3</Version></Project>')
(root / 'LICENSE').write_bytes(newline.join([b'Synthetic MIT notice', b'Copyright fixture', b'']))
plugin = root / 'src/FinalToken.StreamDeck/plugin'
plugin.mkdir(parents=True)
(plugin / 'manifest.json').write_text('{"Version":"0.0.0.0"}')
with patch.object(publish, '__file__', str(root / 'tools/publish.py')):
self.check_package()
def check_package(self):
def fake_publish(command, **kwargs):
stage = Path(command[command.index('-o') + 1])
stage.mkdir(parents=True)
(stage / (stage.name + '.exe')).write_bytes(b'synthetic executable')
with tempfile.TemporaryDirectory(prefix='finaltoken-publish-test-') as temporary:
output = Path(temporary) / 'package'
with patch('sys.argv', ['publish.py', 'win-x64', '--out', str(output)]), \
patch.object(publish.subprocess, 'run', side_effect=fake_publish), \
contextlib.redirect_stdout(io.StringIO()):
publish.main()
version = ET.parse(Path(publish.__file__).resolve().parent.parent / 'Directory.Build.props').findtext('.//Version')
self.assertIsNotNone(version)
manifest = json.loads((output / 'streamdeck/de.finalfactory.finaltoken.sdPlugin/manifest.json').read_text(encoding='utf-8'))
self.assertEqual(version + '.0', manifest['Version'])
license_bytes = (Path(publish.__file__).resolve().parent.parent / 'LICENSE').read_bytes()
self.assertEqual(license_bytes, (output / 'LICENSE').read_bytes())
self.assertEqual(license_bytes, (output / 'streamdeck/de.finalfactory.finaltoken.sdPlugin/LICENSE').read_bytes())
with zipfile.ZipFile(output.with_suffix('.zip')) as bundle:
self.assertEqual(license_bytes, bundle.read('LICENSE'))
if __name__ == '__main__':
unittest.main()