Skip to content

Commit 7ab8127

Browse files
author
Philip de Nier
authored
Merge pull request #33 from bbc/philipn-add-encompass-method
add timerange encompass method
2 parents f94c191 + 4ea5b60 commit 7ab8127

5 files changed

Lines changed: 33 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# mediatimestamp Changelog
22

3+
## 1.7.0
4+
- Added extend_to_encompass_timerange function for immutable.TimeRange.
5+
- Hardcode use of python3.4 in RPM spec file to workaround missing python3 soft
6+
link in recent (>3.4.9) centos python34 RPM.
7+
38
## 1.6.0
49
- Removed the PRESERVE_START and PRESERVE_END rounding options which are used in TimeRange.normalise().
510

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ deb: source deb_dist $(DEBIANOVERRIDES)
9696
$(RPM_PREFIX)/$(MODNAME).spec: rpm_spec
9797

9898
rpm_spec: $(topdir)/setup.py
99-
$(PYTHON3) $(topdir)/setup.py bdist_rpm $(RPM_PARAMS) --spec-only --dist-dir=$(RPM_PREFIX)
99+
$(PYTHON3) $(topdir)/setup.py bdist_rpm $(RPM_PARAMS) --spec-only --dist-dir=$(RPM_PREFIX) --python=python3.4
100100
# END OF RPM SPEC RULES
101101

102102
$(RPMBUILDDIRS):

mediatimestamp/immutable.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,10 @@ def union_with_timerange(self, other):
11241124
if not self.is_contiguous_with_timerange(other):
11251125
raise ValueError("Timeranges {} and {} are not contiguous, so cannot take the union.".format(self, other))
11261126

1127+
return self.extend_to_encompass_timerange(other)
1128+
1129+
def extend_to_encompass_timerange(self, other):
1130+
"""Returns the timerange that encompasses this and the other timerange."""
11271131
if self.is_empty():
11281132
return other
11291133

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
# Basic metadata
2020
name = 'mediatimestamp'
21-
version = '1.6.0'
21+
version = '1.7.0'
2222
description = 'A timestamp library for high precision nanosecond timestamps'
2323
url = 'https://github.com/bbc/rd-apmm-python-lib-mediatimestamp'
2424
author = 'James P. Weaver'

tests/test_immutable.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ def test_normalise(self):
15191519
msg=("{!r}.normalise({}, {}, rounding={}) == {!r}, expected {!r}"
15201520
.format(tr, rate.numerator, rate.denominator, rounding, result, expected)))
15211521

1522-
def test_union(self):
1522+
def test_extend_to_encompass(self):
15231523
test_data = [
15241524
(TimeRange.from_str("()"), TimeRange.from_str("()"),
15251525
TimeRange.from_str("()")),
@@ -1545,15 +1545,35 @@ def test_union(self):
15451545
TimeRange.from_str("[5:0_15:0)")),
15461546
(TimeRange.from_str("()"), TimeRange.from_str("_15:0)"),
15471547
TimeRange.from_str("_15:0)")),
1548+
1549+
# discontiguous
1550+
(TimeRange.from_str("_0:0)"), TimeRange.from_str("(0:0_"),
1551+
TimeRange.from_str("_")),
1552+
(TimeRange.from_str("(0:0_"), TimeRange.from_str("_0:0)"),
1553+
TimeRange.from_str("_")),
1554+
(TimeRange.from_str("[0:0_5:0)"), TimeRange.from_str("(5:0_15:0)"),
1555+
TimeRange.from_str("[0:0_15:0)")),
1556+
(TimeRange.from_str("(5:0_15:0)"), TimeRange.from_str("[0:0_5:0)"),
1557+
TimeRange.from_str("[0:0_15:0)")),
1558+
(TimeRange.from_str("[0:0_5:0)"), TimeRange.from_str("[10:0_15:0)"),
1559+
TimeRange.from_str("[0:0_15:0)")),
1560+
(TimeRange.from_str("[10:0_15:0)"), TimeRange.from_str("[0:0_5:0)"),
1561+
TimeRange.from_str("[0:0_15:0)")),
15481562
]
15491563

15501564
for (first, second, expected) in test_data:
15511565
with self.subTest(first=first, second=second, expected=expected):
1552-
self.assertEqual(first.union_with_timerange(second), expected)
1566+
self.assertEqual(first.extend_to_encompass_timerange(second), expected)
15531567

1568+
def test_union_raises(self):
1569+
# discontiguous part of test_extend_to_encompass raises for a union
15541570
test_data = [
15551571
(TimeRange.from_str("_0:0)"), TimeRange.from_str("(0:0_")),
1572+
(TimeRange.from_str("(0:0_"), TimeRange.from_str("_0:0)")),
1573+
(TimeRange.from_str("[0:0_5:0)"), TimeRange.from_str("(5:0_15:0)")),
1574+
(TimeRange.from_str("(5:0_15:0)"), TimeRange.from_str("[0:0_5:0)")),
15561575
(TimeRange.from_str("[0:0_5:0)"), TimeRange.from_str("[10:0_15:0)")),
1576+
(TimeRange.from_str("[10:0_15:0)"), TimeRange.from_str("[0:0_5:0)")),
15571577
]
15581578

15591579
for (first, second) in test_data:

0 commit comments

Comments
 (0)