Skip to content

Commit

Permalink
rearrange tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lfoppiano committed Feb 13, 2024
1 parent 6103c3f commit bb4ec58
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 139 deletions.
3 changes: 3 additions & 0 deletions tests/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import os

TEST_RESOURCES_PATH = os.path.dirname(__file__)
File renamed without changes.
File renamed without changes.
264 changes: 132 additions & 132 deletions tests/comprehensive.json → tests/resources/comprehensive.json
Original file line number Diff line number Diff line change
@@ -1,133 +1,133 @@
[
{
"material": "P2-Na7/10Mn3/4Fe(1/4-x-y)NixCoyO2",
"parser_output": [
{
"material_string": "P2-Na7/10Mn3/4Fe(1/4-x-y)NixCoyO2",
"material_name": "",
"material_formula": "Na7/10Mn3/4Fe(1/4-x-y)NixCoyO2",
"additives": [],
"phase": "P2",
"oxygen_deficiency": "",
"amounts_x": {
"x": {
"values": [],
"max_value": null,
"min_value": null
},
"y": {
"values": [],
"max_value": null,
"min_value": null
}
},
"elements_x": {},
"composition": [
{
"formula": "Na7/10Mn3/4Fe(1/4-x-y)NixCoyO2",
"amount": "1",
"elements": {
"Na": "0.7",
"Mn": "0.75",
"Fe": "0.25-x-y",
"Ni": "x",
"Co": "y",
"O": "2"
},
"species": {
"Na": "0.7",
"Mn": "0.75",
"Fe": "0.25-x-y",
"Ni": "x",
"Co": "y",
"O": "2"
}
}
]
}
]
},
{
"material": "Mg-doped Na2/3Ni(3/10-x)MgxMn7/10O2",
"parser_output": [
{
"material_string": "Mg-doped Na2/3Ni(3/10-x)MgxMn7/10O2",
"material_name": "",
"material_formula": "Na2/3Ni3/10-xMgxMn7/10O2",
"additives": [
"Mg"
],
"phase": "",
"oxygen_deficiency": "",
"amounts_x": {
"x": {
"values": [],
"max_value": null,
"min_value": null
}
},
"elements_x": {},
"composition": [
{
"formula": "Na2/3Ni3/10-xMgxMn7/10O2",
"amount": "1",
"elements": {
"Na": "0.667",
"Ni": "0.3-x",
"Mg": "x",
"Mn": "0.7",
"O": "2"
},
"species": {
"Na": "0.667",
"Ni": "0.3-x",
"Mg": "x",
"Mn": "0.7",
"O": "2"
}
}
]
}
]
},
{
"material": "Al3+-doped (Zn1/6Ba1/6Ca1/6Sr1/6La1/3)TiO3",
"parser_output": [
{
"material_string": "Al3+-doped (Zn1/6Ba1/6Ca1/6Sr1/6La1/3)TiO3",
"material_name": "",
"material_formula": "(Zn1/6Ba1/6Ca1/6Sr1/6La1/3)TiO3",
"additives": [
"Al3+"
],
"phase": "",
"oxygen_deficiency": "",
"amounts_x": {},
"elements_x": {},
"composition": [
{
"formula": "(Zn1/6Ba1/6Ca1/6Sr1/6La1/3)TiO3",
"amount": "1",
"elements": {
"Zn": "0.167",
"Ba": "0.167",
"Ca": "0.167",
"Sr": "0.167",
"La": "0.333",
"Ti": "1",
"O": "3"
},
"species": {
"Zn": "0.167",
"Ba": "0.167",
"Ca": "0.167",
"Sr": "0.167",
"La": "0.333",
"TiO3": "1"
}
}
]
}
]
}
[
{
"material": "P2-Na7/10Mn3/4Fe(1/4-x-y)NixCoyO2",
"parser_output": [
{
"material_string": "P2-Na7/10Mn3/4Fe(1/4-x-y)NixCoyO2",
"material_name": "",
"material_formula": "Na7/10Mn3/4Fe(1/4-x-y)NixCoyO2",
"additives": [],
"phase": "P2",
"oxygen_deficiency": "",
"amounts_x": {
"x": {
"values": [],
"max_value": null,
"min_value": null
},
"y": {
"values": [],
"max_value": null,
"min_value": null
}
},
"elements_x": {},
"composition": [
{
"formula": "Na7/10Mn3/4Fe(1/4-x-y)NixCoyO2",
"amount": "1",
"elements": {
"Na": "0.7",
"Mn": "0.75",
"Fe": "0.25-x-y",
"Ni": "x",
"Co": "y",
"O": "2"
},
"species": {
"Na": "0.7",
"Mn": "0.75",
"Fe": "0.25-x-y",
"Ni": "x",
"Co": "y",
"O": "2"
}
}
]
}
]
},
{
"material": "Mg-doped Na2/3Ni(3/10-x)MgxMn7/10O2",
"parser_output": [
{
"material_string": "Mg-doped Na2/3Ni(3/10-x)MgxMn7/10O2",
"material_name": "",
"material_formula": "Na2/3Ni3/10-xMgxMn7/10O2",
"additives": [
"Mg"
],
"phase": "",
"oxygen_deficiency": "",
"amounts_x": {
"x": {
"values": [],
"max_value": null,
"min_value": null
}
},
"elements_x": {},
"composition": [
{
"formula": "Na2/3Ni3/10-xMgxMn7/10O2",
"amount": "1",
"elements": {
"Na": "0.667",
"Ni": "0.3-x",
"Mg": "x",
"Mn": "0.7",
"O": "2"
},
"species": {
"Na": "0.667",
"Ni": "0.3-x",
"Mg": "x",
"Mn": "0.7",
"O": "2"
}
}
]
}
]
},
{
"material": "Al3+-doped (Zn1/6Ba1/6Ca1/6Sr1/6La1/3)TiO3",
"parser_output": [
{
"material_string": "Al3+-doped (Zn1/6Ba1/6Ca1/6Sr1/6La1/3)TiO3",
"material_name": "",
"material_formula": "(Zn1/6Ba1/6Ca1/6Sr1/6La1/3)TiO3",
"additives": [
"Al3+"
],
"phase": "",
"oxygen_deficiency": "",
"amounts_x": {},
"elements_x": {},
"composition": [
{
"formula": "(Zn1/6Ba1/6Ca1/6Sr1/6La1/3)TiO3",
"amount": "1",
"elements": {
"Zn": "0.167",
"Ba": "0.167",
"Ca": "0.167",
"Sr": "0.167",
"La": "0.333",
"Ti": "1",
"O": "3"
},
"species": {
"Zn": "0.167",
"Ba": "0.167",
"Ca": "0.167",
"Sr": "0.167",
"La": "0.333",
"TiO3": "1"
}
}
]
}
]
}
]
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 8 additions & 7 deletions tests/test_text2chem.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import unittest

from tests.resources import TEST_RESOURCES_PATH
from text2chem.regex_parser import RegExParser
from text2chem.parser_pipeline import ParserPipelineBuilder
from text2chem.preprocessing_tools.additives_processing import AdditivesProcessing
Expand All @@ -20,7 +21,7 @@
.add_postprocessing(SubstituteAdditives)\
.set_regex_parser(RegExParser)\
.build()
dir_path = os.path.dirname(__file__)



class TestText2chem(unittest.TestCase):
Expand All @@ -29,47 +30,47 @@ def test_formulas(self):
"""
test formulas
"""
testdata = json.loads(open(os.path.join(dir_path, "formulas.json"), encoding="utf-8").read())
testdata = json.loads(open(os.path.join(TEST_RESOURCES_PATH, "formulas.json"), encoding="utf-8").read())
for output, result in self.return_data(testdata):
self.assertEqual(output, result)

def test_additives(self):
"""
test additives
"""
testdata = json.loads(open(os.path.join(dir_path, "additives.json"), encoding="utf-8").read())
testdata = json.loads(open(os.path.join(TEST_RESOURCES_PATH, "additives.json"), encoding="utf-8").read())
for output, result in self.return_data(testdata):
self.assertEqual(output, result)

def test_chemical_names(self):
"""
test chemical names
"""
testdata = json.loads(open(os.path.join(dir_path, "chemical_names.json"), encoding="utf-8").read())
testdata = json.loads(open(os.path.join(TEST_RESOURCES_PATH, "chemical_names.json"), encoding="utf-8").read())
for output, result in self.return_data(testdata):
self.assertEqual(output, result)

def test_mixtures(self):
"""
test mixtures: alloys, solid solutions, composites
"""
testdata = json.loads(open(os.path.join(dir_path, "mixtures.json"), encoding="utf-8").read())
testdata = json.loads(open(os.path.join(TEST_RESOURCES_PATH, "mixtures.json"), encoding="utf-8").read())
for output, result in self.return_data(testdata):
self.assertEqual(output, result)

def test_phases(self):
"""
test phases
"""
testdata = json.loads(open(os.path.join(dir_path, "phases.json"), encoding="utf-8").read())
testdata = json.loads(open(os.path.join(TEST_RESOURCES_PATH, "phases.json"), encoding="utf-8").read())
for output, result in self.return_data(testdata):
self.assertEqual(output, result)

def test_all(self):
"""
comprehensive test
"""
testdata = json.loads(open(os.path.join(dir_path, "comprehensive.json"), encoding="utf-8").read())
testdata = json.loads(open(os.path.join(TEST_RESOURCES_PATH, "comprehensive.json"), encoding="utf-8").read())
for output, result in self.return_data(testdata):
self.assertEqual(output, result)

Expand Down

0 comments on commit bb4ec58

Please sign in to comment.