Skip to content

Commit

Permalink
Merge bd85738 into ed1f686
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Nov 20, 2019
2 parents ed1f686 + bd85738 commit 26017dd
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 4 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ python:
- "3.5"
- "3.6"
- "3.7"
- "3.8"

before_script:
- wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
Expand Down
9 changes: 9 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ Production

:2021.1.7: expected *2020.01*

* `#214 <https://github.com/prjemian/spec2nexus/issues/214>`_
continuous integration testing with py 3.8

* `#213 <https://github.com/prjemian/spec2nexus/issues/213>`_
copy data file to gallery

* `#188 <https://github.com/prjemian/spec2nexus/issues/188>`_
catenate continued lines before parsing data

:2021.1.6: released *2019.11.01*

* `#210 <https://github.com/prjemian/spec2nexus/issues/210>`_
Expand Down
6 changes: 5 additions & 1 deletion src/spec2nexus/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ def interpret(self):
if self.__interpreted__: # do not do this twice
return
self.__lazy_interpret__ = False # set now to avoid recursion
lines = self.raw.splitlines()
lines = self.raw.replace('\\\n', ' ').splitlines()
for _i, line in enumerate(lines, start=1):
if len(line) == 0:
continue # ignore blank lines
Expand Down Expand Up @@ -681,6 +681,10 @@ def addH5writer(self, label, func):
def _interpret_data_row(self, row_text):
buf = {}
for col, val in enumerate(row_text.split()):
if col >= len(self.L):
stop = 1
if col < 0:
stop = 1
label = self.L[col]
buf[label] = float(val)
return buf
Expand Down
14 changes: 11 additions & 3 deletions src/spec2nexus/specplot_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,18 @@ def sorter(d):
]

html = buildIndexHtml(specFile, plot_list, problem_scans)
f = open(htmlFile, "w")
f.write(html)
f.close()
with open(htmlFile, "w") as f:
f.write(html)

# copy specFile to the plot_path, if newer
target = os.path.join(plot_path, os.path.basename(specFile))
if (
not os.path.exists(target)
or
(os.path.getmtime(target) < os.path.getmtime(specFile))
):
shutil.copyfile(specFile, target)

# touch to update the mtime on the plot_path
os.utime(plot_path, None)

Expand Down
2 changes: 2 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def suite(*args, **kw):
from tests import issue119
from tests import issue123
from tests import issue161
from tests import issue188

test_list = [
data_03_06_JanTest,
Expand All @@ -70,6 +71,7 @@ def suite(*args, **kw):
issue119,
issue123,
issue161,
issue188,
]

test_suite = unittest.TestSuite()
Expand Down
90 changes: 90 additions & 0 deletions tests/issue188.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

'''
test punx tests/common module (supports unit testing)
'''

#-----------------------------------------------------------------------------
# :author: Pete R. Jemian
# :email: prjemian@gmail.com
# :copyright: (c) 2014-2019, Pete R. Jemian
#
# Distributed under the terms of the Creative Commons Attribution 4.0 International Public License.
#
# The full license is in the file LICENSE.txt, distributed with this software.
#-----------------------------------------------------------------------------

import os
import sys
import unittest

_test_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
_path = os.path.abspath(os.path.join(_test_path, 'src'))

sys.path.insert(0, _path)
sys.path.insert(0, _test_path)

import spec2nexus.extractSpecScan
import spec2nexus.spec

import tests.common


class Issue188(unittest.TestCase):

def setUp(self):
self.testfile = os.path.join(_path, 'spec2nexus', 'data', 'startup_1.spec')
self.sys_argv0 = sys.argv[0]

def tearDown(self):
sys.argv = [self.sys_argv0,]

def test_scan_unrecognized(self):
self.assertTrue(os.path.exists(self.testfile))

specData = spec2nexus.spec.SpecDataFile(self.testfile)
self.assertTrue(isinstance(specData, spec2nexus.spec.SpecDataFile))

scanNum = 16
scan = specData.getScan(scanNum)
scan.interpret()

self.assertTrue(hasattr(scan, "data"))
self.assertTrue(hasattr(scan, "_unrecognized"))
self.assertEqual(len(scan._unrecognized), 112)

def test_data_file(self):
self.assertTrue(os.path.exists(self.testfile))

specData = spec2nexus.spec.SpecDataFile(self.testfile)
self.assertTrue(isinstance(specData, spec2nexus.spec.SpecDataFile))

for scanNum in specData.getScanNumbers():
scan = specData.getScan(scanNum)
self.assertTrue(isinstance(scan, spec2nexus.spec.SpecDataFileScan))
self.assertTrue(hasattr(scan, "L"))
self.assertIsInstance(scan.L, list)
self.assertTrue(hasattr(scan, "N"))
self.assertIsInstance(scan.N, list)
self.assertGreaterEqual(len(scan.N), 1)
self.assertEqual(len(scan.L), scan.N[0], "scan %s #L line" % scanNum)

self.assertTrue(hasattr(scan, "data"))
self.assertIsInstance(scan.data, dict)
n = len(scan.data.keys())
if n > 0: # if ==0, then no data present
self.assertEqual(len(scan.L), n, "scan %s #L line" % scanNum)


def suite(*args, **kw):
test_suite = unittest.TestSuite()
test_list = [
Issue188,
]
for test_case in test_list:
test_suite.addTest(unittest.makeSuite(test_case))
return test_suite


if __name__ == '__main__':
runner=unittest.TextTestRunner()
runner.run(suite())

0 comments on commit 26017dd

Please sign in to comment.