Skip to content

Commit

Permalink
feat: generate meta value
Browse files Browse the repository at this point in the history
  • Loading branch information
Lan Le committed Aug 30, 2023
1 parent 3045269 commit a8aef77
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 6 deletions.
2 changes: 1 addition & 1 deletion chem_spectra/lib/composer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def gen_simulation_info(self):
return []

def generate_auto_metadata(self):
content = []
content = self.__header_auto_metadata()
if self.auto_metadata is None: return content

for key, value in self.auto_metadata.items():
Expand Down
7 changes: 5 additions & 2 deletions chem_spectra/lib/composer/ni.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@


class NIComposer(BaseComposer):
def __init__(self, core):
super().__init__(core)
def __init__(self, core, auto_metadata=None):
super().__init__(core, auto_metadata)
self.title = core.fname
self.meta = self.__compose()

Expand Down Expand Up @@ -214,6 +214,9 @@ def __compose(self):
meta.extend(self.gen_auto_peaktable())
meta.extend(self.gen_ending())

meta.extend(self.generate_auto_metadata())
meta.extend(self.gen_ending())

meta.extend(self.gen_ending())
return meta

Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/result/edit/edit_meta_13C-DEPT135
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,9 @@ $$ === CHEMSPECTRA PEAK TABLE AUTO ===
4.538400222309662, 5694845.0
##END=


$$ === CHEMSPECTRA AUTO METADATA ===
##END=

##END=

4 changes: 4 additions & 0 deletions tests/fixtures/result/edit/edit_meta_1H
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,9 @@ $$ === CHEMSPECTRA PEAK TABLE AUTO ===
1.40743613258479, 9729036.0
##END=


$$ === CHEMSPECTRA AUTO METADATA ===
##END=

##END=

4 changes: 4 additions & 0 deletions tests/fixtures/result/edit/edit_meta_IR
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,9 @@ $$ === CHEMSPECTRA PEAK TABLE AUTO ===
392.3793345973413, 0.5906721942888722
##END=


$$ === CHEMSPECTRA AUTO METADATA ===
##END=

##END=

4 changes: 4 additions & 0 deletions tests/fixtures/result/im/im_meta_13C-DEPT135
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ $$ === CHEMSPECTRA PEAK TABLE EDIT ===
4.538400222309662, 5694845.0
25.094301409579884, 5687140.0
127.3


$$ === CHEMSPECTRA AUTO METADATA ===
##END=
4 changes: 4 additions & 0 deletions tests/fixtures/result/im/im_meta_1H
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,9 @@ $$ === CHEMSPECTRA PEAK TABLE AUTO ===
7.0099466237990224, 1913776.0
##END=


$$ === CHEMSPECTRA AUTO METADATA ===
##END=

##END=

4 changes: 4 additions & 0 deletions tests/fixtures/result/im/im_meta_IR
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,9 @@ $$ === CHEMSPECTRA PEAK TABLE AUTO ===
745.0957757310398, 0.2787140606224312
##END=


$$ === CHEMSPECTRA AUTO METADATA ===
##END=

##END=

4 changes: 4 additions & 0 deletions tests/fixtures/result/meta_13C-CPD
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,9 @@ $$ === CHEMSPECTRA PEAK TABLE AUTO ===
117.05974904621954, 3088543.0
##END=


$$ === CHEMSPECTRA AUTO METADATA ===
##END=

##END=

3 changes: 3 additions & 0 deletions tests/fixtures/result/meta_13C-DEPT135
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ $$ === CHEMSPECTRA PEAK TABLE EDIT ===
1.0537001328133897, 5016849.0
89.16683096721874, 4


$$ === CHEMSPECTRA AUTO METADATA ===
##END=
4 changes: 4 additions & 0 deletions tests/fixtures/result/meta_1H
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,9 @@ $$ === CHEMSPECTRA PEAK TABLE AUTO ===
7.0099466237990224, 1913776.0
##END=


$$ === CHEMSPECTRA AUTO METADATA ===
##END=

##END=

4 changes: 4 additions & 0 deletions tests/fixtures/result/meta_IR
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,9 @@ $$ === CHEMSPECTRA PEAK TABLE AUTO ===
745.0957757310398, 0.2787140606224312
##END=


$$ === CHEMSPECTRA AUTO METADATA ===
##END=

##END=

4 changes: 4 additions & 0 deletions tests/fixtures/result/meta_SVS-790A_13C
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,9 @@ $$ === CHEMSPECTRA PEAK TABLE AUTO ===
-3.570531620130702, 25781.920000000002
##END=


$$ === CHEMSPECTRA AUTO METADATA ===
##END=

##END=

4 changes: 4 additions & 0 deletions tests/fixtures/result/ps/ps_meta_IR
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,9 @@ $$ === CHEMSPECTRA PEAK TABLE AUTO ===
745.0957757310398, 0.2787140606224312
##END=


$$ === CHEMSPECTRA AUTO METADATA ===
##END=

##END=

8 changes: 5 additions & 3 deletions tests/lib/composer/test_base_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def test_base_composer_generate_auto_metadata_headers(jcamp_file_1h):
composer = BaseComposer(core=base_converter)
headers = composer._BaseComposer__header_auto_metadata()
assert headers == [
'\n',
'$$ === CHEMSPECTRA AUTO METADATA ===\n',
'\n',
'$$ === CHEMSPECTRA AUTO METADATA ===\n',
]

def test_base_composer_generate_auto_metadata(jcamp_file_1h):
Expand All @@ -30,5 +30,7 @@ def test_base_composer_generate_auto_metadata(jcamp_file_1h):
composer = BaseComposer(core=base_converter, auto_metadata=metadata)
auto_metadata = composer.generate_auto_metadata()
assert auto_metadata == [
'##JUST A STRING=just a string value\n'
'\n',
'$$ === CHEMSPECTRA AUTO METADATA ===\n',
'##JUST A STRING=just a string value\n'
]
21 changes: 21 additions & 0 deletions tests/lib/composer/test_ni_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def jcamp_file_1h_edit():
def jcamp_file_ir():
return source_ir

@pytest.fixture
def auto_metadata_dic():
return {"TEST_KEY": "just a string value"}

def test_init_ni_composer_failed():
with pytest.raises(Exception) as error:
_ = NIComposer(None)
Expand All @@ -34,6 +38,23 @@ def test_init_ni_composer_success(jcamp_file_1h):
assert ni_composer is not None
assert ni_composer.core == ni_converter

def test_init_ni_composer_success_with_auto_metadata(jcamp_file_1h, auto_metadata_dic):
base_converter = JcampBaseConverter(jcamp_file_1h)
ni_converter = JcampNIConverter(base=base_converter)
ni_composer = NIComposer(core=ni_converter, auto_metadata=auto_metadata_dic)

assert ni_composer is not None
assert ni_composer.auto_metadata == auto_metadata_dic

def test_composer_auto_metadata(jcamp_file_1h, auto_metadata_dic):
base_converter = JcampBaseConverter(jcamp_file_1h)
ni_converter = JcampNIConverter(base=base_converter)
ni_composer = NIComposer(core=ni_converter, auto_metadata=auto_metadata_dic)

assert ni_composer is not None
assert '$$ === CHEMSPECTRA AUTO METADATA ===\n' in ni_composer.meta
assert '##TEST_KEY=just a string value\n' in ni_composer.meta

def test_ni_composer_header(jcamp_file_1h):
base_converter = JcampBaseConverter(jcamp_file_1h)
ni_converter = JcampNIConverter(base=base_converter)
Expand Down

0 comments on commit a8aef77

Please sign in to comment.