Commit 7e31c473 authored by Kipp Cannon's avatar Kipp Cannon

move segmentsUtils from glue to ligo.segments.utils

parent c4d18abc
Pipeline #34356 failed with stages
in 1 minute and 32 seconds
......@@ -5,24 +5,25 @@ Priority: optional
Standards-Version: 4.1.3
X-Python-Version: >= 2.7
X-Python3-Version: >= 3.4
Build-Depends: debhelper (>= 9),
dh-python,
python-all-dev,
python3-all-dev,
python-pytest,
python3-pytest,
python-setuptools,
python3-setuptools,
python-six,
python3-six
Build-Depends:
debhelper (>= 9),
dh-python,
python-all-dev,
python3-all-dev,
python-pytest,
python3-pytest,
python-setuptools,
python3-setuptools,
python-six,
python3-six
Package: python-ligo-segments
Architecture: any
Depends: ${shlibs:Depends},
${misc:Depends},
${python:Depends},
python-ligo-common,
python-six
Depends: ${shlibs:Depends}, ${misc:Depends}, ${python:Depends},
python-ligo-common,
python-six
Recommends:
lal-python
Description: Representations of semi-open intervals - Python package
ligo-segments provides representation of semi-open intervals or "segments".
The main application of this package is represenation of intervals of time
......@@ -32,11 +33,11 @@ Description: Representations of semi-open intervals - Python package
Package: python3-ligo-segments
Architecture: any
Depends: ${shlibs:Depends},
${misc:Depends},
${python3:Depends},
python3-ligo-common,
python3-six
Depends: ${shlibs:Depends}, ${misc:Depends}, ${python3:Depends},
python3-ligo-common,
python3-six
Recommends:
lal-python3
Description: Representations of semi-open intervals - Python 3 package
ligo-segments provides representation of semi-open intervals or "segments".
The main application of this package is represenation of intervals of time
......
......@@ -27,6 +27,7 @@ infinity object used to define semi-infinite and infinite segments.
Summary: %{summary}
Requires: python-six
Requires: ligo-common
Recommends: python2-lal
%{?python_provide:%python_provide python2-%{srcname}}
......@@ -38,6 +39,7 @@ infinity object used to define semi-infinite and infinite segments.
Summary: %{summary}
Requires: python%{python3_pkgversion}-six
Requires: python%{python3_pkgversion}-ligo-common
Recommends: python3-lal
%{?python_provide:%python_provide python%{python3_pkgversion}-%{srcname}}
......
......@@ -38,7 +38,7 @@ infinity object used to define semi-infinite and infinite segments.
See also:
glue.segmentsUtils
ligo.segments.utils
"""
......
This diff is collapsed.
PYTHON ?= python
check : \
segments_verify
segments_verify \
segments_utils_verify
@echo "All Tests Passed"
define printpassfail
{ echo "Pass" ; true ; } || { echo "Fail" ; false ; }
endef
segments_verify :
segments_verify segments_utils_verify :
@echo "=== start $@ ===>"
$(PYTHON) $@.py && $(printpassfail)
@echo "<=== end $@ ==="
from functools import reduce
import itertools
import random
from six.moves import StringIO
import sys
import unittest
# FIXME: why is this needed?
import pkg_resources
from ligo import segments
from ligo.segments import utils as segmentsUtils
import verifyutils
verifyutils.segments = segments
#
# How many times to repeat the algebraic tests
#
algebra_repeats = 8000
algebra_listlength = 200
#
# Define the components of the test suite.
#
class test_segwizard(unittest.TestCase):
def test_fromsegwizard(self):
"""
Test segwizard parsing.
"""
data = StringIO("""# This is a comment
# This is another comment
# Again a comment
1 10 100 90
2 110 120 10# Here's a comment
3 125 130 5 # Another one
4 0 200 200""")
correct = segments.segmentlist([segments.segment(10, 100), segments.segment(110, 120), segments.segment(125, 130), segments.segment(0, 200)])
self.assertEqual(correct, segmentsUtils.fromsegwizard(data, strict=True))
def test_tofromseqwizard(self):
"""
Check that the segwizard writing routine's output is parsed
correctly.
"""
data = StringIO()
correct = segments.segmentlist([segments.segment(10, 100), segments.segment(110, 120), segments.segment(125, 130), segments.segment(0, 200)])
segmentsUtils.tosegwizard(data, correct)
data.seek(0)
self.assertEqual(correct, segmentsUtils.fromsegwizard(data, strict=True))
class test_vote(unittest.TestCase):
def test_vote(self):
"""
Test vote().
"""
for i in range(algebra_repeats):
seglists = []
for j in range(random.randint(0, 10)):
seglists.append(verifyutils.random_coalesced_list(algebra_listlength))
n = random.randint(0, len(seglists))
correct = reduce(lambda x, y: x | y, (votes and reduce(lambda a, b: a & b, votes) or segments.segmentlist() for votes in itertools.combinations(seglists, n)), segments.segmentlist())
self.assertEqual(correct, segmentsUtils.vote(seglists, n))
#
# Construct and run the test suite.
#
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(test_segwizard))
suite.addTest(unittest.makeSuite(test_vote))
sys.exit(not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment