74 lines
2.5 KiB
JavaScript
74 lines
2.5 KiB
JavaScript
// test/03a_cameraPose.test.js
|
|
const { execSync } = require('child_process');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
describe('Camera Pose Script', () => {
|
|
const projectRoot = path.resolve(__dirname, '..');
|
|
const scriptPath = path.resolve(projectRoot, 'programs/03a_cameraPose.py');
|
|
const timestamp = 1778819665744;
|
|
const screenshotDir = path.join(__dirname, 'data', 'screenShots');
|
|
const detectionFiles = [
|
|
'snapshot_video0_1778819665744_aruco_detection.json',
|
|
'snapshot_video1_1778819665744_aruco_detection.json',
|
|
];
|
|
const robotFile = path.resolve(projectRoot, 'test/data/robot/robot.json');
|
|
const sceneFile = path.join(screenshotDir, `scene_${timestamp}.json`);
|
|
const outputFile = path.join(screenshotDir, `scene_${timestamp}_cameras.json`);
|
|
|
|
beforeEach(() => {
|
|
detectionFiles.forEach((file) => {
|
|
const src = path.join(screenshotDir, file);
|
|
if (!fs.existsSync(src)) {
|
|
throw new Error(`Missing test fixture detection file: ${src}`);
|
|
}
|
|
});
|
|
|
|
if (!fs.existsSync(sceneFile)) {
|
|
throw new Error(`Missing scene file generated by step 2: ${sceneFile}`);
|
|
}
|
|
|
|
if (fs.existsSync(outputFile)) {
|
|
fs.unlinkSync(outputFile);
|
|
}
|
|
});
|
|
|
|
afterEach(() => {
|
|
// Keep the generated scene and camera JSON in the screenshot directory.
|
|
});
|
|
|
|
test('should exist and be executable', () => {
|
|
expect(fs.existsSync(scriptPath)).toBe(true);
|
|
});
|
|
|
|
test('should have scene file', () => {
|
|
expect(fs.existsSync(sceneFile)).toBe(true);
|
|
});
|
|
|
|
test('should have robot file', () => {
|
|
expect(fs.existsSync(robotFile)).toBe(true);
|
|
});
|
|
|
|
test('should compute camera poses with timestamp parameter', () => {
|
|
// Führe das Python-Skript mit den korrekten Parametern aus
|
|
const cmd = `python "${scriptPath}" -scene "${sceneFile}" -robot "${robotFile}" -out "${outputFile}"`;
|
|
|
|
try {
|
|
execSync(cmd, { stdio: 'inherit', cwd: projectRoot });
|
|
} catch (error) {
|
|
throw new Error(`Failed to compute camera poses: ${error.message}`);
|
|
}
|
|
// Überprüfe, ob die erwartete Ausgabedatei erstellt wurde
|
|
expect(fs.existsSync(outputFile)).toBe(true);
|
|
|
|
// Prüfe den Inhalt der JSON-Datei
|
|
const jsonData = JSON.parse(fs.readFileSync(outputFile, 'utf8'));
|
|
expect(jsonData).toBeDefined();
|
|
expect(typeof jsonData).toBe('object');
|
|
expect(jsonData).toHaveProperty('camera_poses');
|
|
});
|
|
|
|
test('should handle timestamp parameter correctly', () => {
|
|
expect(timestamp).toBe(1778819665744);
|
|
});
|
|
}); |