-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rewriting qe for easier future implementations
- Loading branch information
Showing
8 changed files
with
315 additions
and
371 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,22 +8,22 @@ | |
LONG_DESCRIPTION = f.read() | ||
|
||
setup( | ||
name='aton', | ||
version=__version__, | ||
author='Pablo Gila-Herranz', | ||
author_email='[email protected]', | ||
description=DESCRIPTION, | ||
long_description=LONG_DESCRIPTION, | ||
long_description_content_type='text/markdown', | ||
packages=['aton'], | ||
install_requires=['numpy', 'pandas'], | ||
extras_requires={ | ||
'dev': ['pytest', 'twine'] | ||
}, | ||
python_requires='>=3', | ||
license='AGPL-3.0', | ||
keywords=['Aton', 'Neutron', 'Neutron research', 'Spectra', 'Inelastic Neutron Scattering', 'INS', 'Ab-initio', 'DFT', 'Density Functional Theory', 'MD', 'Molecular Dynamics', 'Quantum ESPRESSO', 'Phonopy', 'CASTEP'], | ||
classifiers= [ | ||
name = 'aton', | ||
version = __version__, | ||
author = 'Pablo Gila-Herranz', | ||
author_email = '[email protected]', | ||
description = DESCRIPTION, | ||
long_description = LONG_DESCRIPTION, | ||
long_description_content_type = 'text/markdown', | ||
packages = ['aton'], | ||
install_requires = ['numpy', 'pandas', 'scipy', 'matplotlib'], | ||
extras_requires = { | ||
'dev': ['pytest', 'twine', 'build'] | ||
}, | ||
python_requires = '>=3', | ||
license = 'AGPL-3.0', | ||
keywords = ['Aton', 'Neutron', 'Neutron research', 'Spectra', 'Inelastic Neutron Scattering', 'INS', 'Ab-initio', 'DFT', 'Density Functional Theory', 'MD', 'Molecular Dynamics', 'Quantum ESPRESSO', 'Phonopy', 'CASTEP'], | ||
classifiers = [ | ||
"Development Status :: 5 - Production/Stable", | ||
"Natural Language :: English", | ||
"Intended Audience :: Science/Research", | ||
|
@@ -33,3 +33,4 @@ | |
"Operating System :: Other OS", | ||
] | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
from aton.text import edit | ||
from aton import file | ||
|
||
|
||
folder = 'tests/samples/' | ||
sample = folder + 'sample.txt' | ||
sample_copy = folder + 'sample_copy.txt' | ||
|
||
|
||
def test_insert_at(): | ||
file.copy(sample, sample_copy) | ||
edit.insert_at(filepath=sample_copy, text='MIDDLE', position=1) | ||
edit.insert_at(filepath=sample_copy, text='START', position=0) | ||
edit.insert_at(filepath=sample_copy, text='END', position=-1) | ||
with open(sample_copy, 'r') as f: | ||
assert f.read() == 'START\nline1\nMIDDLE\nline2\nline3\nline4\nline5\nline6\nline7\nline8\nline9\nEND' | ||
file.remove(sample_copy) | ||
|
||
|
||
def test_insert_under(): | ||
file.copy(sample, sample_copy) | ||
edit.insert_under(filepath=sample_copy, key='5', text='!!!', skips=0) | ||
with open(sample_copy, 'r') as f: | ||
assert f.read() == 'line1\nline2\nline3\nline4\nline5\n!!!\nline6\nline7\nline8\nline9' | ||
file.copy(sample, sample_copy) | ||
edit.insert_under(filepath=sample_copy, key='5', text='!!!', skips=-1) | ||
with open(sample_copy, 'r') as f: | ||
assert f.read() == 'line1\nline2\nline3\nline4\n!!!\nline5\nline6\nline7\nline8\nline9' | ||
file.copy(sample, sample_copy) | ||
edit.insert_under(filepath=sample_copy, key=r'l[a-z]*5', text='!!!', regex=True) | ||
with open(sample_copy, 'r') as f: | ||
assert f.read() == 'line1\nline2\nline3\nline4\nline5\n!!!\nline6\nline7\nline8\nline9' | ||
file.remove(sample_copy) | ||
|
||
|
||
def test_replace(): | ||
file.copy(sample, sample_copy) | ||
edit.replace(filepath=sample_copy, key='line5', text='!!!') | ||
with open(sample_copy, 'r') as f: | ||
assert f.read() == 'line1\nline2\nline3\nline4\n!!!\nline6\nline7\nline8\nline9' | ||
file.remove(sample_copy) | ||
|
||
|
||
def test_replace_line(): | ||
file.copy(sample, sample_copy) | ||
edit.replace_line(filepath=sample_copy, key='line5', text='!!!') | ||
with open(sample_copy, 'r') as f: | ||
assert f.read() == 'line1\nline2\nline3\nline4\n!!!\nline6\nline7\nline8\nline9' | ||
file.copy(sample, sample_copy) | ||
edit.replace_line(filepath=sample_copy, key='line5', text='') | ||
with open(sample_copy, 'r') as f: | ||
assert f.read() == 'line1\nline2\nline3\nline4\nline6\nline7\nline8\nline9' | ||
file.remove(sample_copy) | ||
|
||
|
||
def test_replace_between(): | ||
file.copy(sample, sample_copy) | ||
edit.replace_between(filepath=sample_copy, key1='line4', key2='line7', text='!!!') | ||
with open(sample_copy, 'r') as f: | ||
assert f.read() == 'line1\nline2\nline3\nline4\n!!!\nline7\nline8\nline9' | ||
file.remove(sample_copy) | ||
|
||
|
||
def test_remove_between(): | ||
file.copy(sample, sample_copy) | ||
edit.replace_between(filepath=sample_copy, key1='line4', key2='line7', text='') | ||
with open(sample_copy, 'r') as f: | ||
assert f.read() == 'line1\nline2\nline3\nline4\nline7\nline8\nline9' | ||
file.remove(sample_copy) | ||
|
||
|
||
def test_delete_under(): | ||
file.copy(sample, sample_copy) | ||
edit.delete_under(filepath=sample_copy, key='5') | ||
with open(sample_copy, 'r') as f: | ||
assert f.read() == 'line1\nline2\nline3\nline4\nline5' | ||
file.remove(sample_copy) | ||
|
||
|
||
def test_correct_with_dict(): | ||
correct = {'line1': 'text', 'line5': ''} | ||
file.copy(sample, sample_copy) | ||
edit.correct_with_dict(filepath=sample_copy, correct=correct) | ||
with open(sample_copy, 'r') as f: | ||
assert f.read() == 'text\nline2\nline3\nline4\n\nline6\nline7\nline8\nline9' | ||
file.remove(sample_copy) | ||
|
||
|
||
def test_template(): | ||
try: | ||
file.remove(sample_copy) | ||
except: | ||
pass | ||
try: | ||
edit.from_template(old=sample, new=sample_copy, correct={'line':''}, comment='!!!') | ||
with open(sample_copy, 'r') as f: | ||
content = f.read() | ||
assert content == '!!!\n1\n2\n3\n4\n5\n6\n7\n8\n9' | ||
except: | ||
assert False | ||
try: | ||
file.remove(sample_copy) | ||
except: | ||
pass | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
import thotpy as th | ||
from aton.text import extract | ||
|
||
|
||
def test_extract_number(): | ||
assert th.extract.number(' test = 123 number ', 'test') == 123.0 | ||
assert th.extract.number(' test 123 number ', 'test') == 123.0 | ||
assert extract.number(' test = 123 number ', 'test') == 123.0 | ||
assert extract.number(' test 123 number ', 'test') == 123.0 | ||
|
||
|
||
def test_extract_string(): | ||
assert th.extract.string(text=' test = "hello" stop ', name='test', stop='stop', strip=True) == 'hello' | ||
assert th.extract.string(text=' test "hello" stop ', name='test', stop='stop', strip=True) == 'hello' | ||
assert th.extract.string(text=" test 'hello' stop ", name='test', stop='stop', strip=True) == 'hello' | ||
assert th.extract.string(text=" test 'hello' stop ", name='test', stop='stop', strip=False) == "'hello'" | ||
assert extract.string(text=' test = "hello" stop ', name='test', stop='stop', strip=True) == 'hello' | ||
assert extract.string(text=' test "hello" stop ', name='test', stop='stop', strip=True) == 'hello' | ||
assert extract.string(text=" test 'hello' stop ", name='test', stop='stop', strip=True) == 'hello' | ||
assert extract.string(text=" test 'hello' stop ", name='test', stop='stop', strip=False) == "'hello'" | ||
|
||
|
||
def test_extract_column(): | ||
assert th.extract.column(' 123 456.5 789 ', 2) == 789 | ||
assert extract.column(' 123 456.5 789 ', 2) == 789 | ||
|
||
|
||
def test_extract_coords(): | ||
assert th.extract.coords('coordinates: 1.0, 2.0 and 3 these were the coordinates') ==[1.0, 2.0, 3.0] | ||
assert extract.coords('coordinates: 1.0, 2.0 and 3 these were the coordinates') ==[1.0, 2.0, 3.0] | ||
|
||
|
||
def test_extract_element(): | ||
string = ' element I Lead Pb Nitrogen H2, Xx2 fake element, O Oxygen, He4 isotope Ag Element ' | ||
assert th.extract.element(text=string, index=0) == 'I' | ||
assert th.extract.element(text=string, index=1) == 'Pb' | ||
assert th.extract.element(text=string, index=2) == 'H2' | ||
assert th.extract.element(text=string, index=3) == 'O' | ||
assert th.extract.element(text=string, index=4) == 'He4' | ||
assert th.extract.element(text=string, index=5) == 'Ag' | ||
assert extract.element(text=string, index=0) == 'I' | ||
assert extract.element(text=string, index=1) == 'Pb' | ||
assert extract.element(text=string, index=2) == 'H2' | ||
assert extract.element(text=string, index=3) == 'O' | ||
assert extract.element(text=string, index=4) == 'He4' | ||
assert extract.element(text=string, index=5) == 'Ag' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.