Files
appRobotVideoControls/test/0_path_OK.test.js
chk f37097ea96 2 Camera Detection
Checke wo sich im Bild die Kamera befindet
2026-05-25 16:50:48 +02:00

100 lines
3.0 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const PROJECT_PATH = process.cwd()
const TEST_PATH = path.join(__dirname, '.');
const SCRIPT_FILE = path.join(PROJECT_PATH, 'programs', '1_detect_aruco_observations.py');
const SOURCE_DIR = path.join(__dirname,'data', 'screenShots');
const TARGET_DIR = path.join(__dirname,'data', 'screenshots', '1778819665744_detection_testResults');
const PYTHON_CMD = process.platform === 'win32' ? 'python' : 'python3';
const TEST_SETUP_FILE = path.join(TEST_PATH, 'data', '0_testSetup.json');
const ROBOT_PATH = path.join(__dirname, 'data', 'robot', 'robot.json');
const SCRIPT_FILE_2 = path.join(PROJECT_PATH, 'programs', '2_estimate_camera_pose_from_aruco_json.py');
const cam = {
id : 'cam1',
image: 'snapshot_video1_1779690911822.jpg',
intrinsics: path.join(PROJECT_PATH, 'data', 'settings','callibration_cam0.npz')
};
// Passe diese Werte an deine echten Daten an
const pathsToCheck = {
SOURCE_DIR,
SCRIPT_FILE,
ROBOT_PATH,
SCRIPT_FILE_2,
NPZ_PATH: cam.intrinsics,
IMAGE_PATH: path.join(SOURCE_DIR, cam.image),
PYTHON_SCRIPT: path.join(PROJECT_PATH, 'programs', '1_detect_aruco_observations.py'),
TEST_SETUP_FILE,
};
describe('Check if Paths exist', () => {
test('Each relevant Python File etc.', () => {
const missing = [];
for (const [name, filePath] of Object.entries(pathsToCheck)) {
if (!filePath || !fs.existsSync(filePath)) {
missing.push(`${name} -> ${filePath}`);
}
}
if (missing.length > 0) {
throw new Error(
'Folgende Pfade fehlen oder sind ungültig:\n' +
missing.join('\n')
);
}
});
test('Test if files in Setup exist', () => {
console.log('TEST_PATH:', TEST_PATH);
console.log('PROJECT_PATH:', PROJECT_PATH);
console.log('SOURCE_DIR:', SOURCE_DIR);
if (!fs.existsSync(TEST_SETUP_FILE)) {
throw new Error(`Test-Setup Datei fehlt: ${TEST_SETUP_FILE}`);
}
const raw = fs.readFileSync(TEST_SETUP_FILE, 'utf8');
const data = JSON.parse(raw);
const missing = [];
data.forEach((testCase, i) => {
const r = testCase.robot.map(i => i.replace("TEST_PATH", TEST_PATH).replace("PROJECT_PATH", PROJECT_PATH));
const pathR = path.join(r.map(p => p.toString()).join(path.sep));
if (!pathR || !fs.existsSync(pathR)) {
missing.push(`${name} -> ${filePath}`);
}
testCase.image.forEach((img, j) => {
const imgPath = path.join(img.file.map(i => i.replace("TEST_PATH", TEST_PATH).replace("PROJECT_PATH", PROJECT_PATH)).join(path.sep));
if (!imgPath || !fs.existsSync(imgPath)) {
missing.push(`TestCase ${i} Image ${j} -> ${imgPath}`);
}
});
});
console.log('Missing files in test setup:', missing);
if (missing.length > 0) {
throw new Error(
'Folgende Dateien aus dem Test-Setup fehlen oder sind ungültig:\n' +
missing.join('\n')
);
}
});
});