mirror of
https://gitlab.com/Thoscellen/Wallset.git
synced 2025-05-31 19:04:51 +02:00
Ajuste les chemins d'accès relatifs pour le débug local.
WIP: Adapter la configuration pour la CI/CD.
This commit is contained in:
parent
d665e1f12e
commit
112b745a45
14
.vscode/launch.json
vendored
14
.vscode/launch.json
vendored
@ -2,17 +2,17 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "dev-test Valid_set",
|
"name": "Gen Valid_set",
|
||||||
"cwd": "${workspaceFolder}/src",
|
"cwd": "${workspaceFolder}/src",
|
||||||
"type": "node",
|
"type": "node",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"runtimeExecutable": "npm",
|
"runtimeExecutable": "npm",
|
||||||
"runtimeArgs": [
|
"runtimeArgs": [
|
||||||
"run",
|
"run",
|
||||||
"dev-test"
|
"start"
|
||||||
],
|
],
|
||||||
"env": {
|
"env": {
|
||||||
"ENTRY_FOLDER": "test",
|
"ENTRY_FOLDER": "${workspaceFolder}/test",
|
||||||
"PACKAGE_NAME": "valid_set"
|
"PACKAGE_NAME": "valid_set"
|
||||||
},
|
},
|
||||||
"skipFiles": [
|
"skipFiles": [
|
||||||
@ -20,22 +20,22 @@
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "dev-start Valid_set",
|
"name": "Test Valid_set",
|
||||||
"cwd": "${workspaceFolder}/src",
|
"cwd": "${workspaceFolder}/src",
|
||||||
"type": "node",
|
"type": "node",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"runtimeExecutable": "npm",
|
"runtimeExecutable": "npm",
|
||||||
"runtimeArgs": [
|
"runtimeArgs": [
|
||||||
"run",
|
"run",
|
||||||
"dev-start"
|
"test"
|
||||||
],
|
],
|
||||||
"env": {
|
"env": {
|
||||||
"ENTRY_FOLDER": "test",
|
"ENTRY_FOLDER": "${workspaceFolder}/test",
|
||||||
"PACKAGE_NAME": "valid_set"
|
"PACKAGE_NAME": "valid_set"
|
||||||
},
|
},
|
||||||
"skipFiles": [
|
"skipFiles": [
|
||||||
"<node_internals>/**"
|
"<node_internals>/**"
|
||||||
],
|
],
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -6,7 +6,7 @@ const iptc = require("node-iptc");
|
|||||||
// find all images
|
// find all images
|
||||||
const slug = process.env["PACKAGE_NAME"];
|
const slug = process.env["PACKAGE_NAME"];
|
||||||
const root = process.env["ENTRY_FOLDER"];
|
const root = process.env["ENTRY_FOLDER"];
|
||||||
let workingDirectory = path.join("../..", root, slug);
|
let workingDirectory = path.join(root, slug);
|
||||||
|
|
||||||
// extract metadata from them
|
// extract metadata from them
|
||||||
fs.readdir(workingDirectory, (err, files) => {
|
fs.readdir(workingDirectory, (err, files) => {
|
||||||
@ -22,10 +22,8 @@ fs.readdir(workingDirectory, (err, files) => {
|
|||||||
// iterate each files
|
// iterate each files
|
||||||
files.filter(file => path.extname(file) == '.jpg').forEach(image => {
|
files.filter(file => path.extname(file) == '.jpg').forEach(image => {
|
||||||
buffer = fs.readFileSync(path.join(workingDirectory, image));
|
buffer = fs.readFileSync(path.join(workingDirectory, image));
|
||||||
//if (err) { throw err };
|
|
||||||
// extract metadata
|
// extract metadata
|
||||||
let metadata = iptc(buffer);
|
let metadata = iptc(buffer);
|
||||||
// fill object
|
|
||||||
theme.imageFilename ||= metadata.special_instructions + "_*" + path.extname(image);
|
theme.imageFilename ||= metadata.special_instructions + "_*" + path.extname(image);
|
||||||
theme.imageCredits ||= metadata.copyright_notice;
|
theme.imageCredits ||= metadata.copyright_notice;
|
||||||
theme.displayName ||= metadata.headline;
|
theme.displayName ||= metadata.headline;
|
||||||
|
@ -5,12 +5,8 @@ const Ajv = require("ajv").default;
|
|||||||
const ajv = new Ajv({ allErrors: true });
|
const ajv = new Ajv({ allErrors: true });
|
||||||
require("ajv-errors")(ajv);
|
require("ajv-errors")(ajv);
|
||||||
|
|
||||||
//let root, slug;
|
const themeSchemaFile = "json_theme_schema.jsonc";
|
||||||
//let workingDirectory = path.join(root, slug);
|
let manifest;
|
||||||
//console.log(`👷♂️ Working with ‘${slug}’ slug.`);
|
|
||||||
|
|
||||||
const themeSchemaFile = "src/test_manifest_job/json_theme_schema.jsonc";
|
|
||||||
let wppManifest;
|
|
||||||
let validator;
|
let validator;
|
||||||
let files;
|
let files;
|
||||||
let workingDirectory;
|
let workingDirectory;
|
||||||
@ -21,17 +17,17 @@ function leftOuterJoin(leftArray, rightArray) {
|
|||||||
}, rightArray);
|
}, rightArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
function flatReferences(wppManifest) {
|
function flatReferences(manifest) {
|
||||||
allImageIds = [
|
allImageIds = [
|
||||||
wppManifest.dayHighlight,
|
manifest.dayHighlight,
|
||||||
wppManifest.nightHighlight,
|
manifest.nightHighlight,
|
||||||
...wppManifest.dayImageList,
|
...manifest.dayImageList,
|
||||||
...wppManifest.nightImageList,
|
...manifest.nightImageList,
|
||||||
...(wppManifest.sunsetImageList || []),
|
...(manifest.sunsetImageList || []),
|
||||||
...(wppManifest.sunriseImageList || [])
|
...(manifest.sunriseImageList || [])
|
||||||
];
|
];
|
||||||
return allImageIds.filter(el => el !== undefined).map(el => {
|
return allImageIds.filter(el => el !== undefined).map(el => {
|
||||||
return wppManifest.imageFilename.replace("*", el);
|
return manifest.imageFilename.replace("*", el);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,16 +44,16 @@ describe('Mandatory Checks', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
step('Manifest is an existing json file', function () {
|
step('Manifest is an existing json file', function () {
|
||||||
wppManifest = JSON.parse(fs.readFileSync(path.join(workingDirectory, "theme.json"), "utf8"));
|
manifest = JSON.parse(fs.readFileSync(path.join(workingDirectory, "theme.json"), "utf8"));
|
||||||
});
|
});
|
||||||
|
|
||||||
step('Manifest passes the schema', function () {
|
step('Manifest passes the schema', function () {
|
||||||
const isValid = validator(wppManifest);
|
const isValid = validator(manifest);
|
||||||
if (!isValid) expect.fail(`\n\t• ${validator.errors.map(el => { return el.message; }).join('\n\t• ')}`);
|
if (!isValid) expect.fail(`\n\t• ${validator.errors.map(el => { return el.message; }).join('\n\t• ')}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
step('There are no missing files', function () {
|
step('There are no missing files', function () {
|
||||||
let references = flatReferences(wppManifest);
|
let references = flatReferences(manifest);
|
||||||
references.push("theme.json");
|
references.push("theme.json");
|
||||||
let missings = leftOuterJoin(references, files);
|
let missings = leftOuterJoin(references, files);
|
||||||
expect(missings,
|
expect(missings,
|
||||||
@ -66,7 +62,7 @@ describe('Mandatory Checks', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
step('There are no orphan files', function () {
|
step('There are no orphan files', function () {
|
||||||
let references = flatReferences(wppManifest);
|
let references = flatReferences(manifest);
|
||||||
let orphans = leftOuterJoin(files.filter(x => x !== "theme.json"), references);
|
let orphans = leftOuterJoin(files.filter(x => x !== "theme.json"), references);
|
||||||
expect(orphans,
|
expect(orphans,
|
||||||
`The following orphan file${(orphans.length > 1) ? "s are" : " is"} not referenced in this theme.json. Consider removing the file${(orphans.length > 1) ? "s" : ""} or referencing ${(orphans.length > 1) ? "them" : "it"} in the theme.json:\n\t• ${orphans.join('\n\t• ')}\n`
|
`The following orphan file${(orphans.length > 1) ? "s are" : " is"} not referenced in this theme.json. Consider removing the file${(orphans.length > 1) ? "s" : ""} or referencing ${(orphans.length > 1) ? "them" : "it"} in the theme.json:\n\t• ${orphans.join('\n\t• ')}\n`
|
||||||
|
@ -4,10 +4,8 @@
|
|||||||
"description": "Generate the manifest file of the project, based on metadata contained in the pictures.",
|
"description": "Generate the manifest file of the project, based on metadata contained in the pictures.",
|
||||||
"main": "build-manifest.js",
|
"main": "build-manifest.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev-start": "",
|
"start": "node build-manifest.js",
|
||||||
"start": "",
|
"test": "mocha --require mocha-steps --colors manifest.spec.js"
|
||||||
"dev-test": "mocha --require mocha-steps --colors manifest.spec.js",
|
|
||||||
"test": ""
|
|
||||||
},
|
},
|
||||||
"author": "Simon",
|
"author": "Simon",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import glob
|
import glob
|
||||||
from PIL import Image, ImageStat
|
from PIL import Image, ImageStat
|
||||||
# from _pytest.outcomes import skip
|
|
||||||
from iteration_utilities import duplicates
|
from iteration_utilities import duplicates
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import json
|
import json
|
||||||
@ -9,12 +8,8 @@ import pytest
|
|||||||
|
|
||||||
|
|
||||||
def validate_brightness_image(working_path, theme_config, high_light, image_list, brightness_way):
|
def validate_brightness_image(working_path, theme_config, high_light, image_list, brightness_way):
|
||||||
# get a dict<filename:string, mean:int> of all images to scan them
|
|
||||||
image_pattern = theme_config.get("imageFilename")
|
image_pattern = theme_config.get("imageFilename")
|
||||||
|
|
||||||
# if image_filenames is None:
|
|
||||||
image_filenames = {}.fromkeys(glob.glob(str(Path(working_path, image_pattern))))
|
image_filenames = {}.fromkeys(glob.glob(str(Path(working_path, image_pattern))))
|
||||||
|
|
||||||
# generate an image statistics for each images
|
# generate an image statistics for each images
|
||||||
for an_imagefile in image_filenames:
|
for an_imagefile in image_filenames:
|
||||||
this_image = Image.open(an_imagefile).convert("L")
|
this_image = Image.open(an_imagefile).convert("L")
|
||||||
@ -32,7 +27,6 @@ def validate_brightness_image(working_path, theme_config, high_light, image_list
|
|||||||
an_image = image_pattern.replace("*", str(theme_config.get(high_light)))
|
an_image = image_pattern.replace("*", str(theme_config.get(high_light)))
|
||||||
ref_est_file = str(Path(working_path, an_image))
|
ref_est_file = str(Path(working_path, an_image))
|
||||||
assert actual_est_image == ref_est_file, f"✖ {brightness_way} image is {actual_est_image}, but the {high_light} image is {ref_est_file}."
|
assert actual_est_image == ref_est_file, f"✖ {brightness_way} image is {actual_est_image}, but the {high_light} image is {ref_est_file}."
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# if not highlight is given in theme.json, we suppose that brightest images are in the daylist
|
# if not highlight is given in theme.json, we suppose that brightest images are in the daylist
|
||||||
ref_est_files = []
|
ref_est_files = []
|
||||||
@ -40,7 +34,6 @@ def validate_brightness_image(working_path, theme_config, high_light, image_list
|
|||||||
an_image = image_pattern.replace('*', str(an_id))
|
an_image = image_pattern.replace('*', str(an_id))
|
||||||
ref_est_files.append(str(Path(working_path, an_image)))
|
ref_est_files.append(str(Path(working_path, an_image)))
|
||||||
assert actual_est_image in ref_est_files, f"✖ {brightness_way} image {actual_est_image} was not found in the '{image_list}' attribute."
|
assert actual_est_image in ref_est_files, f"✖ {brightness_way} image {actual_est_image} was not found in the '{image_list}' attribute."
|
||||||
# print(f"✔ {brightness_way} image is {actual_est_image}, as expected.")
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -70,11 +63,9 @@ def test_darkest_image(working_path, manifest):
|
|||||||
|
|
||||||
def test_image_size(working_path, manifest):
|
def test_image_size(working_path, manifest):
|
||||||
image_filename = manifest["imageFilename"].replace("*", str(manifest["dayImageList"][0]))
|
image_filename = manifest["imageFilename"].replace("*", str(manifest["dayImageList"][0]))
|
||||||
img = Image.open(Path(working_path, image_filename))
|
w, h = Image.open(Path(working_path, image_filename)).size
|
||||||
w, h = img.size
|
|
||||||
assert w >= 1920 and h >= 1080, f"✖ Image size is too small (must be at least 1920×1080, is {w}×{h})"
|
assert w >= 1920 and h >= 1080, f"✖ Image size is too small (must be at least 1920×1080, is {w}×{h})"
|
||||||
assert w >= h, "✖ Image orientation is portrait (must be landscape or square)"
|
assert w >= h, "✖ Image orientation is portrait (must be landscape or square)"
|
||||||
# print(f"✔ Images are big enough ({w}×{h}) and landscape.")
|
|
||||||
|
|
||||||
def test_overlapping_images(manifest):
|
def test_overlapping_images(manifest):
|
||||||
jointed_lists = manifest.get("dayImageList")
|
jointed_lists = manifest.get("dayImageList")
|
||||||
@ -86,5 +77,4 @@ def test_overlapping_images(manifest):
|
|||||||
str_dup_refs = [manifest["imageFilename"].replace("*", str(int)) for int in dup_refs]
|
str_dup_refs = [manifest["imageFilename"].replace("*", str(int)) for int in dup_refs]
|
||||||
separator = ", "
|
separator = ", "
|
||||||
|
|
||||||
assert not dup_refs, f"✖ Some images are referenced twice or more times: {separator.join(str_dup_refs)}."
|
assert not dup_refs, f"✖ Some images are referenced twice or more: {separator.join(str_dup_refs)}."
|
||||||
# print("✔ There is no overlapping references of images in the theme.json.")
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user