Skip to content
This repository has been archived by the owner on Oct 11, 2021. It is now read-only.

Commit

Permalink
ci: validate JSON files with schemas in VSCode (#429)
Browse files Browse the repository at this point in the history
* fix: remove Strength parameter from expected test recipe
* fix: write CSV test file to output dir
  • Loading branch information
redeboer authored Jan 10, 2021
1 parent 7704913 commit f9cb35e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 47 deletions.
19 changes: 16 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@
"git.rebaseWhenSync": true,
"githubPullRequests.telemetry.enabled": false,
"gitlens.advanced.telemetry.enabled": false,
"json.schemas": [
{
"fileMatch": ["*recipe*.json", "test_write_read_*.json"],
"url": "./src/expertsystem/schemas/amplitude-model.json"
},
{
"fileMatch": ["*particle*.json"],
"url": "./src/expertsystem/schemas/particle-list.json"
}
],
"python.analysis.autoImportCompletions": false,
"python.analysis.diagnosticMode": "workspace",
"python.formatting.provider": "black",
Expand All @@ -68,15 +78,18 @@
"rewrap.wrappingColumn": 79,
"search.exclude": {
"**/tests/**/__init__.py": true,
"reqs/3.*/*.txt": true,
"docs/tox.ini": true,
"reqs/3.*/*.txt": true,
"tests/tox.ini": true
},
"telemetry.enableCrashReporter": false,
"telemetry.enableTelemetry": false,
"yaml.schemas": {
"./src/expertsystem/schemas/amplitude-model.json": ["*recipe.y*ml"],
"./src/expertsystem/schemas/particle-list.json": ["*particle.y*ml"],
"./src/expertsystem/schemas/amplitude-model.json": [
"*recipe*.y*ml",
"test_write_read_*.yml"
],
"./src/expertsystem/schemas/particle-list.json": ["*particle*.y*ml"],
"https://raw.githubusercontent.com/readthedocs/readthedocs.org/master/readthedocs/rtd_tests/fixtures/spec/v2/schema.yml": ".readthedocs.yml"
}
}
72 changes: 34 additions & 38 deletions tests/unit/io/expected_recipe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,35 @@ Kinematics:
ID: 4

Parameters:
- Name: &par1 strength_incoherent
Type: Strength
Value: 1
Fix: true
- Name: &par2 Magnitude_J/psi(1S)_to_f(0)(980)_0+gamma_1;f(0)(980)_to_pi0_0+pi0_0;
- Name: &par1 Magnitude_J/psi(1S)_to_f(0)(980)_0+gamma_1;f(0)(980)_to_pi0_0+pi0_0;
Type: Magnitude
Value: 1.0
- Name: &par3 Phase_J/psi(1S)_to_f(0)(980)_0+gamma_1;f(0)(980)_to_pi0_0+pi0_0;
- Name: &par2 Phase_J/psi(1S)_to_f(0)(980)_0+gamma_1;f(0)(980)_to_pi0_0+pi0_0;
Type: Phase
Value: 0.0
- Name: &par4 Magnitude_J/psi(1S)_to_f(0)(1500)_0+gamma_1;f(0)(1500)_to_pi0_0+pi0_0;
- Name: &par3 Magnitude_J/psi(1S)_to_f(0)(1500)_0+gamma_1;f(0)(1500)_to_pi0_0+pi0_0;
Type: Magnitude
Value: 1.0
- Name: &par5 Phase_J/psi(1S)_to_f(0)(1500)_0+gamma_1;f(0)(1500)_to_pi0_0+pi0_0;
- Name: &par4 Phase_J/psi(1S)_to_f(0)(1500)_0+gamma_1;f(0)(1500)_to_pi0_0+pi0_0;
Type: Phase
Value: 0.0
- Name: &par6 MesonRadius_J/psi(1S)
- Name: &par5 MesonRadius_J/psi(1S)
Type: MesonRadius
Value: 1.0
Fix: true
- Name: &par7 Position_f(0)(980)
- Name: &par6 Position_f(0)(980)
Value: 0.99
- Name: &par8 Width_f(0)(980)
- Name: &par7 Width_f(0)(980)
Value: 0.06
- Name: &par9 MesonRadius_f(0)(980)
- Name: &par8 MesonRadius_f(0)(980)
Value: 1.0
Fix: true
Type: MesonRadius
- Name: &par10 Position_f(0)(1500)
- Name: &par9 Position_f(0)(1500)
Value: 1.506
- Name: &par11 Width_f(0)(1500)
- Name: &par10 Width_f(0)(1500)
Value: 0.112
- Name: &par12 MesonRadius_f(0)(1500)
- Name: &par11 MesonRadius_f(0)(1500)
Value: 1.0
Fix: true
Type: MesonRadius
Expand All @@ -63,8 +59,8 @@ Intensity:
Amplitudes:
- Class: CoefficientAmplitude
Component: J/psi(1S)_-1_to_f(0)(980)_0+gamma_-1;f(0)(980)_0_to_pi0_0+pi0_0;
Magnitude: *par2
Phase: *par3
Magnitude: *par1
Phase: *par2
Amplitude:
Class: SequentialAmplitude
Amplitudes:
Expand Down Expand Up @@ -100,8 +96,8 @@ Intensity:
- 2
- Class: CoefficientAmplitude
Component: J/psi(1S)_-1_to_f(0)(1500)_0+gamma_-1;f(0)(1500)_0_to_pi0_0+pi0_0;
Magnitude: *par4
Phase: *par5
Magnitude: *par3
Phase: *par4
Amplitude:
Class: SequentialAmplitude
Amplitudes:
Expand Down Expand Up @@ -140,8 +136,8 @@ Intensity:
Amplitudes:
- Class: CoefficientAmplitude
Component: J/psi(1S)_1_to_f(0)(980)_0+gamma_-1;f(0)(980)_0_to_pi0_0+pi0_0;
Magnitude: *par2
Phase: *par3
Magnitude: *par1
Phase: *par2
Amplitude:
Class: SequentialAmplitude
Amplitudes:
Expand Down Expand Up @@ -177,8 +173,8 @@ Intensity:
- 2
- Class: CoefficientAmplitude
Component: J/psi(1S)_1_to_f(0)(1500)_0+gamma_-1;f(0)(1500)_0_to_pi0_0+pi0_0;
Magnitude: *par4
Phase: *par5
Magnitude: *par3
Phase: *par4
Amplitude:
Class: SequentialAmplitude
Amplitudes:
Expand Down Expand Up @@ -217,8 +213,8 @@ Intensity:
Amplitudes:
- Class: CoefficientAmplitude
Component: J/psi(1S)_-1_to_f(0)(980)_0+gamma_1;f(0)(980)_0_to_pi0_0+pi0_0;
Magnitude: *par2
Phase: *par3
Magnitude: *par1
Phase: *par2
Amplitude:
Class: SequentialAmplitude
Amplitudes:
Expand Down Expand Up @@ -254,8 +250,8 @@ Intensity:
- 2
- Class: CoefficientAmplitude
Component: J/psi(1S)_-1_to_f(0)(1500)_0+gamma_1;f(0)(1500)_0_to_pi0_0+pi0_0;
Magnitude: *par4
Phase: *par5
Magnitude: *par3
Phase: *par4
Amplitude:
Class: SequentialAmplitude
Amplitudes:
Expand Down Expand Up @@ -294,8 +290,8 @@ Intensity:
Amplitudes:
- Class: CoefficientAmplitude
Component: J/psi(1S)_1_to_f(0)(980)_0+gamma_1;f(0)(980)_0_to_pi0_0+pi0_0;
Magnitude: *par2
Phase: *par3
Magnitude: *par1
Phase: *par2
Amplitude:
Class: SequentialAmplitude
Amplitudes:
Expand Down Expand Up @@ -331,8 +327,8 @@ Intensity:
- 2
- Class: CoefficientAmplitude
Component: J/psi(1S)_1_to_f(0)(1500)_0+gamma_1;f(0)(1500)_0_to_pi0_0+pi0_0;
Magnitude: *par4
Phase: *par5
Magnitude: *par3
Phase: *par4
Amplitude:
Class: SequentialAmplitude
Amplitudes:
Expand Down Expand Up @@ -428,20 +424,20 @@ Dynamics:
Type: NonDynamic
FormFactor:
Type: BlattWeisskopf
MesonRadius: *par6
MesonRadius: *par5
f(0)(980):
Type: RelativisticBreitWigner
PoleParameters:
Real: *par7
Imaginary: *par8
Real: *par6
Imaginary: *par7
FormFactor:
Type: BlattWeisskopf
MesonRadius: *par9
MesonRadius: *par8
f(0)(1500):
Type: RelativisticBreitWigner
PoleParameters:
Real: *par10
Imaginary: *par11
Real: *par9
Imaginary: *par10
FormFactor:
Type: BlattWeisskopf
MesonRadius: *par12
MesonRadius: *par11
15 changes: 9 additions & 6 deletions tests/unit/io/test_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def particle_selection(particle_database: ParticleCollection):


def test_not_implemented_errors(
output_dir, particle_selection: ParticleCollection
output_dir: str, particle_selection: ParticleCollection
):
with pytest.raises(NotImplementedError):
io.load(__file__)
Expand All @@ -35,7 +35,9 @@ def test_not_implemented_errors(
io.write(666, output_dir + "wont_work_anyway.yml")


def test_serialization(output_dir, particle_selection: ParticleCollection):
def test_serialization(
output_dir: str, particle_selection: ParticleCollection
):
assert len(particle_selection) == 181
io.write(particle_selection, output_dir + "particle_selection.yml")
asdict = io.asdict(particle_selection)
Expand All @@ -56,7 +58,7 @@ def model(
return jpsi_to_gamma_pi_pi_helicity_amplitude_model

@pytest.fixture(scope="session")
def imported_dict(self, output_dir, model: AmplitudeModel):
def imported_dict(self, output_dir: str, model: AmplitudeModel):
output_filename = output_dir + "JPsiToGammaPi0Pi0_heli_recipe.yml"
asdict = io.asdict(model)
io.write(model, output_filename)
Expand Down Expand Up @@ -180,7 +182,7 @@ def test_expected_recipe_shape(
else:
expected_items = sorted(expected_section, key=lambda p: p["Name"])
imported_items = sorted(imported_section, key=lambda p: p["Name"])
# assert len(imported_items) == len(expected_items)
assert len(imported_items) == len(expected_items)
for imported, expected in zip(imported_items, expected_items):
assert imported == expected

Expand All @@ -193,20 +195,21 @@ def model(
return jpsi_to_gamma_pi_pi_canonical_amplitude_model

@pytest.fixture(scope="session")
def imported_dict(self, output_dir, model: AmplitudeModel):
def imported_dict(self, output_dir: str, model: AmplitudeModel):
output_filename = output_dir + "JPsiToGammaPi0Pi0_cano_recipe.yml"
asdict = io.asdict(model)
io.write(model, output_filename)
return asdict

def test_not_implemented_writer(
self,
output_dir: str,
jpsi_to_gamma_pi_pi_canonical_amplitude_model: AmplitudeModel,
):
with pytest.raises(NotImplementedError):
io.write(
instance=jpsi_to_gamma_pi_pi_canonical_amplitude_model,
filename="JPsiToGammaPi0Pi0.csv",
filename=output_dir + "JPsiToGammaPi0Pi0.csv",
)

def test_particle_section(self, imported_dict):
Expand Down

0 comments on commit f9cb35e

Please sign in to comment.