def test_set_consecutive_before_eq():
	"""Test setting consecutive ranges to the same value."""
	rm = RangeMap({1: 'a', 2: 'b', 3: 'c'})
	print_underlying(rm)
	rm.set('b', 1, 2)
	print_underlying(rm)
	assert rm == RangeMap({1: 'b', 3: 'c'})
def test_set_beg():
	"""Test setting the beginning."""
	rm = RangeMap()
	rm.set('a', stop=4)
	with pytest.raises(KeyError):
		rm[4]
	assert rm[3] == 'a'
def test_set_beg():
	"""Test setting the beginning."""
	rm = RangeMap()
	rm.set('a', stop=4)
	with pytest.raises(KeyError):
		rm[4]
	assert rm[3] == 'a'
def test_set_consecutive_before_eq():
	"""Test setting consecutive ranges to the same value."""
	rm = RangeMap({1: 'a', 2: 'b', 3: 'c'})
	print_underlying(rm)
	rm.set('b', 1, 2)
	print_underlying(rm)
	assert rm == RangeMap({1: 'b', 3: 'c'})
def test_break_up_existing_internal_interval():
	"""Test breaking up an existing interval."""
	rm = RangeMap({1: 'a', 2: 'b'})
	rm.set('d', start=1, stop=1.5)
	assert rm[1] == 'd'
	assert rm[1.5] == 'a'
	assert rm[2] == 'b'
	assert rm[3] == 'b'
def test_break_up_existing_open_end_interval():
	"""Test breaking up an existing open interval at the end."""
	rm = RangeMap({1: 'a', 2: 'b'})
	rm.set('d', start=2, stop=2.5)
	assert rm[1] == 'a'
	assert rm[2] == 'd'
	assert rm[2.5] == 'b'
	assert rm[3] == 'b'
def test_break_up_existing_open_end_interval():
	"""Test breaking up an existing open interval at the end."""
	rm = RangeMap({1: 'a', 2: 'b'})
	rm.set('d', start=2, stop=2.5)
	assert rm[1] == 'a'
	assert rm[2] == 'd'
	assert rm[2.5] == 'b'
	assert rm[3] == 'b'
def test_set_closed_interval_end():
	"""Test setting a closed range on the end."""
	rm = RangeMap({1: 'a', 2: 'b'})
	rm.set('c', start=3, stop=4)
	assert rm[1] == 'a'
	assert rm[2] == 'b'
	assert rm[3] == 'c'
	assert rm[4] == 'b'
def test_set_closed_interval_end():
	"""Test setting a closed range on the end."""
	rm = RangeMap({1: 'a', 2: 'b'})
	rm.set('c', start=3, stop=4)
	assert rm[1] == 'a'
	assert rm[2] == 'b'
	assert rm[3] == 'c'
	assert rm[4] == 'b'
예제 #10
0
def test_break_up_existing_internal_interval():
	"""Test breaking up an existing interval."""
	rm = RangeMap({1: 'a', 2: 'b'})
	rm.set('d', start=1, stop=1.5)
	assert rm[1] == 'd'
	assert rm[1.5] == 'a'
	assert rm[2] == 'b'
	assert rm[3] == 'b'
def test_overwrite_multiple_internal():
	"""Test overwriting multiple adjoining intervals."""
	rm = RangeMap({1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e'})
	rm.set('z', start=2, stop=5)
	assert rm[1] == 'a'
	assert rm[2] == 'z'
	assert rm[3] == 'z'
	assert rm[4] == 'z'
	assert rm[5] == 'e'
def test_dates():
	"""Test using dates."""
	rm = RangeMap()
	rm.set('b', datetime.date(1936, 12, 11))
	rm.set('a', datetime.date(1952, 2, 6))
	assert rm[datetime.date(1945, 1, 1)] == 'b'
	assert rm[datetime.date(1965, 4, 6)] == 'a'
	with pytest.raises(KeyError):
		rm[datetime.date(1900, 1, 1)]
예제 #13
0
def test_dates():
	"""Test using dates."""
	rm = RangeMap()
	rm.set('b', datetime.date(1936, 12, 11))
	rm.set('a', datetime.date(1952, 2, 6))
	assert rm[datetime.date(1945, 1, 1)] == 'b'
	assert rm[datetime.date(1965, 4, 6)] == 'a'
	with pytest.raises(KeyError):
		rm[datetime.date(1900, 1, 1)]
예제 #14
0
def test_overwrite_multiple_internal():
	"""Test overwriting multiple adjoining intervals."""
	rm = RangeMap({1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e'})
	rm.set('z', start=2, stop=5)
	assert rm[1] == 'a'
	assert rm[2] == 'z'
	assert rm[3] == 'z'
	assert rm[4] == 'z'
	assert rm[5] == 'e'
def test_overwrite_all():
	"""Test overwriting the entire mapping."""
	rm = RangeMap({1: 'a', 2: 'b'})
	rm.set('z', start=0)
	with pytest.raises(KeyError):
		rm[-1]
	assert rm[0] == 'z'
	assert rm[1] == 'z'
	assert rm[2] == 'z'
	assert rm[3] == 'z'
예제 #16
0
def test_overwrite_all():
	"""Test overwriting the entire mapping."""
	rm = RangeMap({1: 'a', 2: 'b'})
	rm.set('z', start=0)
	with pytest.raises(KeyError):
		rm[-1]
	assert rm[0] == 'z'
	assert rm[1] == 'z'
	assert rm[2] == 'z'
	assert rm[3] == 'z'
예제 #17
0
def test_set_existing_interval():
	"""Test setting an exact existing range."""
	rm = RangeMap({1: 'a', 2: 'b'})
	rm.set('c', start=1, stop=2)
	print_underlying(rm)
	assert rm[1] == 'c'
	assert rm[2] == 'b'
	assert rm[3] == 'b'
	assert rm == RangeMap({1: 'c', 2: 'b'})
	with pytest.raises(KeyError):
		rm[0]
예제 #18
0
def test_closed():
	"""Test a closed RangeMap."""
	rm = RangeMap()
	rm.set('a', start=1, stop=2)
	print_underlying(rm)
	assert rm[1] == 'a'
	assert rm[1.9] == 'a'
	with pytest.raises(KeyError):
		rm[2]
	with pytest.raises(KeyError):
		rm[0]
def test_default_value():
	"""Test setting just a default value."""
	rm = RangeMap(default_value=None)
	print(rm)
	assert rm[1] is None
	assert rm[-2] is None
	rm.set('a', start=1)
	print(rm)
	assert rm[0] is None
	assert rm[1] == 'a'
	assert rm[2] == 'a'
예제 #20
0
def test_default_value():
	"""Test setting just a default value."""
	rm = RangeMap(default_value=None)
	print(rm)
	assert rm[1] is None
	assert rm[-2] is None
	rm.set('a', start=1)
	print(rm)
	assert rm[0] is None
	assert rm[1] == 'a'
	assert rm[2] == 'a'
def test_set_existing_interval():
	"""Test setting an exact existing range."""
	rm = RangeMap({1: 'a', 2: 'b'})
	rm.set('c', start=1, stop=2)
	print_underlying(rm)
	assert rm[1] == 'c'
	assert rm[2] == 'b'
	assert rm[3] == 'b'
	assert rm == RangeMap({1: 'c', 2: 'b'})
	with pytest.raises(KeyError):
		rm[0]
def test_closed():
	"""Test a closed RangeMap."""
	rm = RangeMap()
	rm.set('a', start=1, stop=2)
	print_underlying(rm)
	assert rm[1] == 'a'
	assert rm[1.9] == 'a'
	with pytest.raises(KeyError):
		rm[2]
	with pytest.raises(KeyError):
		rm[0]
def test_alter_beg():
	"""Test altering the beginning."""
	rm = RangeMap({1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e'})
	rm.set('z', stop=3)
	assert rm[0] == 'z'
	assert rm[1] == 'z'
	assert rm[2] == 'z'
	assert rm[3] == 'c'
	assert rm[4] == 'd'
	assert rm[5] == 'e'
	rm.set('y', stop=3)
	assert rm == RangeMap({3: 'c', 4: 'd', 5: 'e'}, default_value='y')
예제 #24
0
def test_alter_beg():
	"""Test altering the beginning."""
	rm = RangeMap({1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e'})
	rm.set('z', stop=3)
	assert rm[0] == 'z'
	assert rm[1] == 'z'
	assert rm[2] == 'z'
	assert rm[3] == 'c'
	assert rm[4] == 'd'
	assert rm[5] == 'e'
	rm.set('y', stop=3)
	assert rm == RangeMap({3: 'c', 4: 'd', 5: 'e'}, default_value='y')
예제 #25
0
def test_simple_set():
	"""Test set."""
	rm = RangeMap()
	rm.set('a', start=1)
	print_underlying(rm)
	assert rm[1] == 'a'
	assert rm[2] == 'a'
	with pytest.raises(KeyError):
		rm[0]
	rm.set('b', start=2)
	assert rm[1] == 'a'
	assert rm[2] == 'b'
	assert rm[3] == 'b'
def test_simple_set():
	"""Test set."""
	rm = RangeMap()
	rm.set('a', start=1)
	print_underlying(rm)
	assert rm[1] == 'a'
	assert rm[2] == 'a'
	with pytest.raises(KeyError):
		rm[0]
	rm.set('b', start=2)
	assert rm[1] == 'a'
	assert rm[2] == 'b'
	assert rm[3] == 'b'
def test_set_consecutive_after_eq():
	"""Test setting consecutive ranges to the same value."""
	rm = RangeMap({1: 'a', 2: 'b', 3: 'c'})
	rm.set('a', 2, 3)
	assert rm == RangeMap({1: 'a', 3: 'c'})
예제 #28
0
def test_start_gt_stop():
	rm = RangeMap({1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e'}, default_value='z')
	with pytest.raises(ValueError):
		rm.set('a', start=3, stop=2)
	with pytest.raises(ValueError):
		rm.get_range(start=3, stop=2)
예제 #29
0
def test_from_mapping():
	"""Test creating a RangeMap from a mapping."""
	rm = RangeMap()
	rm.set('a', start=1)
	rm.set('b', start=2)
	assert rm == RangeMap({1: 'a', 2: 'b'})
def test_from_mapping():
	"""Test creating a RangeMap from a mapping."""
	rm = RangeMap()
	rm.set('a', start=1)
	rm.set('b', start=2)
	assert rm == RangeMap({1: 'a', 2: 'b'})
def test_start_gt_stop():
	rm = RangeMap({1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e'}, default_value='z')
	with pytest.raises(ValueError):
		rm.set('a', start=3, stop=2)
	with pytest.raises(ValueError):
		rm.get_range(start=3, stop=2)
예제 #32
0
def test_set_consecutive_after_eq():
	"""Test setting consecutive ranges to the same value."""
	rm = RangeMap({1: 'a', 2: 'b', 3: 'c'})
	rm.set('a', 2, 3)
	assert rm == RangeMap({1: 'a', 3: 'c'})
def test_whole_range():
	"""Test setting the whole range."""
	rm = RangeMap()
	rm.set('a')
	assert rm[1] == 'a'
	assert rm[-1] == 'a'
def test_set_consecutive_between_eq():
	"""Test setting consecutive ranges to the same value."""
	rm = RangeMap({1: 'a', 2: 'b', 3: 'c', 4: 'b'})
	rm.set('b', 3, 4)
	assert rm == RangeMap({1: 'a', 2: 'b'})
예제 #35
0
def test_whole_range():
	"""Test setting the whole range."""
	rm = RangeMap()
	rm.set('a')
	assert rm[1] == 'a'
	assert rm[-1] == 'a'
예제 #36
0
def test_set_consecutive_between_eq():
	"""Test setting consecutive ranges to the same value."""
	rm = RangeMap({1: 'a', 2: 'b', 3: 'c', 4: 'b'})
	rm.set('b', 3, 4)
	assert rm == RangeMap({1: 'a', 2: 'b'})