Select Git revision
generate_openfisca_tests_yaml.ts
-
David Smadja authoredDavid Smadja authored
generate_openfisca_tests_yaml.ts 15.47 KiB
import type { Situation } from "@openfisca/json-model"
import commandLineArgs from "command-line-args"
import fs from "fs-extra"
import path from "path"
import YAML from "js-yaml"
import testCasesCoreUnknown from "@leximpact/socio-fiscal-openfisca-json/test_cases.json"
import {
summaryCalculatedVariablesName,
otherCalculatedVariablesName,
variableSummaryByName,
} from "$lib/variables"
import { nonVirtualVariablesName } from "$lib/decompositions"
import type { EntityByKey, Entity, GroupEntity } from "@openfisca/json-model"
import { entityByKey } from "$lib/entities"
type JsonObject = { [key: string]: any }
const optionsDefinitions = [
{
alias: "s",
help: "don't log anything",
name: "silent",
type: Boolean,
},
{
alias: "v",
help: "verbose logs",
name: "verbose",
type: Boolean,
},
{
alias: "y",
help: "Year to ask as simulation output",
name: "year",
type: Number,
},
{
alias: "t",
help: "Single Test-Case to run",
name: "testcase",
type: String,
},
{
defaultOption: true,
help: "Directory to write OpenFisca test YAML files",
name: "outdir",
type: String,
},
]
const options = commandLineArgs(optionsDefinitions)
async function fetchWithRetries(
url: string,
options: RequestInit,
maxRetries = 5,
delay = 10000,
) {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
const response = await fetch(url, options)
if (response.ok) {
return response
}
console.warn(
`Calling Openfisca API. Attempt ${attempt} : Failed with status ${response.status}`,
)
} catch (error) {
console.error(`Error on attempt ${attempt} :`, error)