Skip to content
Snippets Groups Projects
Select Git revision
  • master
  • cleanup
2 results

requirements.txt

Blame
  • This project manages its dependencies using pip. Learn more
    generate_openfisca_tests_yaml.ts 19.53 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"
    import { spawn } from "child_process"
    
    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) {