Lichtkasten v0.1: Culling, IPTC (PM-kompatibel), Vorlagen, FTP/Immich, Lightroom-Bridge

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012bGzgsxrmbBhDzeMV2L57D
This commit is contained in:
Lichtkasten DevandClaude Opus 5.5 committed 2026-11-03 22:40:28 +00:00
commit e13cbf416d
37 files changed
+4431

No files matched your search

@@ -0,0 +1,93 @@
import XCTest
@testable import LichtkastenCore
final class VariableTests: XCTestCase {
func testExpandsFileAndDateVariables() {
let ctx = VariableContext.make(fileURL: URL(fileURLWithPath: "/x/IMG_0001.CR3"),
exif: ["DateTimeOriginal": "2026:11:03 14:22:01", "Model": "Canon EOS R5"])
XCTAssertEqual(VariableExpander.expand("{filenamebase} {date} {isodate} {model}", context: ctx),
"IMG_0001 03.11.2026 2026-11-03 Canon EOS R5")
XCTAssertEqual(VariableExpander.expand("{unbekannt}", context: ctx), "{unbekannt}")
}
func testCodeReplacement() {
let codes = CodeReplacements.load(tabDelimited: "bvb\tBorussia Dortmund\tBVB\n# Kommentar\ns04\tFC Schalke 04\tS04\n")
XCTAssertEqual(codes.expand("\\bvb\\ gegen \\s04#2\\"), "Borussia Dortmund gegen S04")
XCTAssertEqual(codes.expand("Pfad C:\\temp\\x"), "Pfad C:\\temp\\x")
}
}
final class TemplateTests: XCTestCase {
let pmXMP = """
<x:xmpmeta xmlns:x="adobe:ns:meta/">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:Iptc4xmpCore="http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/"
xmlns:photomechanic="http://ns.camerabits.com/photomechanic/1.0/"
photoshop:City="Dortmund" photoshop:Credit="Agentur XY" photomechanic:Foo="bar">
<dc:creator><rdf:Seq><rdf:li>Max Müller</rdf:li></rdf:Seq></dc:creator>
<dc:description><rdf:Alt><rdf:li xml:lang="x-default">{city}, {date} – Fußball</rdf:li></rdf:Alt></dc:description>
<dc:subject><rdf:Bag><rdf:li>Sport</rdf:li><rdf:li>Fußball</rdf:li></rdf:Bag></dc:subject>
<Iptc4xmpCore:CreatorContactInfo rdf:parseType="Resource">
<Iptc4xmpCore:CiEmailWork>max@example.de</Iptc4xmpCore:CiEmailWork>
</Iptc4xmpCore:CreatorContactInfo>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
"""
func testImportPMTemplate() throws {
let t = try XMPTemplateIO.parse(data: Data(pmXMP.utf8))
XCTAssertEqual(t.values.text["city"], "Dortmund")
XCTAssertEqual(t.values.text["credit"], "Agentur XY")
XCTAssertEqual(t.values.text["creator"], "Max Müller")
XCTAssertEqual(t.values.text["caption"], "{city}, {date} – Fußball")
XCTAssertEqual(t.values.lists["keywords"], ["Sport", "Fußball"])
XCTAssertEqual(t.values.text["ciEmail"], "max@example.de")
XCTAssertEqual(t.extras["\(XMPNamespace.photomechanic)|Foo"], "bar")
}
func testExportRoundTrip() throws {
let t = try XMPTemplateIO.parse(data: Data(pmXMP.utf8))
let again = try XMPTemplateIO.parse(data: Data(XMPTemplateIO.export(t).utf8))
XCTAssertEqual(again.values, t.values)
XCTAssertEqual(again.extras, t.extras)
}
func testApplyAppendsKeywords() {
var existing = IPTCValues()
existing.lists["keywords"] = ["Sport"]
existing.text["headline"] = "Alt"
let t = IPTCTemplate(name: "t", values: IPTCValues(text: ["headline": "Neu"], lists: ["keywords": ["Sport", "BVB"]]))
let r = t.apply(to: existing)
XCTAssertEqual(r.lists["keywords"], ["Sport", "BVB"])
XCTAssertEqual(r.text["headline"], "Neu")
}
func testWriterArgumentsForJPEGAndRAW() throws {
let w = MetadataWriter(exiftool: ExifTool(executable: URL(fileURLWithPath: "/usr/bin/true")))
var v = IPTCValues()
v.text["city"] = "Dortmund"
v.lists["keywords"] = ["A", "B"]
let fields = [IPTCField.byID["city"]!, IPTCField.byID["keywords"]!]
let jpeg = try w.arguments(values: v, fields: fields, targetKind: .jpeg)
XCTAssertTrue(jpeg.contains("-IPTC:City=Dortmund"))
XCTAssertTrue(jpeg.contains("-XMP-photoshop:City=Dortmund"))
XCTAssertTrue(jpeg.contains("-IPTC:CodedCharacterSet=UTF8"))
XCTAssertEqual(jpeg.filter { $0 == "-IPTC:Keywords=A" || $0 == "-IPTC:Keywords=B" }.count, 2)
let raw = try w.arguments(values: v, fields: fields, targetKind: .raw)
XCTAssertFalse(raw.contains { $0.hasPrefix("-IPTC:") })
}
}
final class LightroomJobTests: XCTestCase {
func testResultParsing() {
let r = LightroomJobResult.parse("id=abc\nstatus=done\nimported=2\nexported=/a/b.jpg\nerror=x\n")
XCTAssertEqual(r.id, "abc")
XCTAssertTrue(r.ok)
XCTAssertEqual(r.imported, 2)
XCTAssertEqual(r.exported.map(\.path), ["/a/b.jpg"])
}
}