示例#1
0
def test_delete():
    c = Cell('!!n=v|', True)
    c.del_attr('n')
    assert c.string == '!!|'
    c = Cell('!!n=v1 m=w n="v2"|', True)
    c.del_attr('n')
    assert c.string == '!! m=w|'
    # Test removing a non-existing attribute
    c.del_attr('n')
示例#2
0
 def test_delete(self):
     c = Cell('!!n=v|', True)
     c.del_attr('n')
     self.assertEqual(c.string, '!!|')
     c = Cell('!!n=v1 m=w n="v2"|', True)
     c.del_attr('n')
     self.assertEqual(c.string, '!!m=w |')
     # Test removing a non-existing attribute
     c.del_attr('n')
示例#3
0
 def test_cached_attrs_expiry(self):
     """_cached_attrs should expire when _match_cache is updated."""
     c = Cell('\n!v', True)
     # Fill _match_cache and _attrs_match_cache
     self.assertEqual(c.attrs, {})
     # Invalidate both caches
     c.insert(2, 'a|')
     # Update _match_cache
     self.assertEqual(c.value, 'v')
     # _attrs_match_cache should not be valid
     self.assertEqual(c.attrs, {'a': ''})
示例#4
0
def test_cached_attrs_expiry():
    """_cached_attrs should expire when _match_cache is updated."""
    c = Cell('\n!v', True)
    # Fill _match_cache and _attrs_match_cache
    assert c.attrs == {}
    # Invalidate both caches
    c.insert(2, 'a|')
    # Update _match_cache
    assert c.value == 'v'
    # _attrs_match_cache should not be valid
    assert c.attrs == {'a': ''}
示例#5
0
 def test_space_or_quote_at_set_boundary(self):
     c = Cell('!!n=v|', True)
     c.set_attr('m', 'w')
     self.assertEqual(c.string, '!!n=v m="w"|')
     c = Cell('!! n=v |', True)
     c.set_attr('m', 'w')
     self.assertEqual(c.string, '!! n=v m="w" |')
示例#6
0
 def test_inline_cell_no_attr_span_set(self):
     c = Cell('!! 00', True)
     c.set_attr('n', 'v')
     self.assertEqual(c.string, '!! n="v" | 00')
     c = Cell('!! 00', True)
     c.set_attr('n', '')
     self.assertEqual(c.string, '!! n | 00')
示例#7
0
def test_space_or_quote_at_set_boundary():
    c = Cell('!!n=v|', True)
    c.set_attr('m', 'w')
    assert c.string == '!!n=v m="w"|'
    c = Cell('!! n=v |', True)
    c.set_attr('m', 'w')
    assert c.string == '!! n=v m="w" |'
示例#8
0
def test_inline_cell_no_attr_span_set():
    c = Cell('!! 00', True)
    c.set_attr('n', 'v')
    assert c.string == '!! n="v" | 00'
    c = Cell('!! 00', True)
    c.set_attr('n', '')
    assert c.string == '!! n | 00'
示例#9
0
 def test_set_overwrite(self):
     c = Cell('\n! n=v | 00', True)
     # Set a new value for an existing attribute
     c.set_attr('n', 'w')
     # Set a new attribute
     c.set_attr('n2', 'v2')
     self.assertEqual(c.string, '\n! n="w" n2="v2" | 00')
示例#10
0
def test_set_overwrite():
    c = Cell('\n! n=v | 00', True)
    # Set a new value for an existing attribute
    c.set_attr('n', 'w')
    # Set a new attribute
    c.set_attr('n2', 'v2')
    assert c.string == '\n! n="w" n2="v2" | 00'
示例#11
0
 def test_value(self):
     c = Cell('\n| a ')
     self.assertEqual(' a ', c.value)
     self.assertEqual(repr(c), 'Cell(\'\\n| a \')')
     self.assertEqual(c.attrs, {})
     # Use _cached_attrs
     self.assertEqual(c.attrs, {})
     # Inline _header cell
     c = Cell('|| 01 ', True)
     self.assertEqual(c.value, ' 01 ')
     # Inline non-_header cell
     c = Cell('|| 01 ', False)
     self.assertEqual(c.value, ' 01 ')
     # Set a new value
     c.value = '\na\na'
     self.assertEqual(c.value, '\na\na')
示例#12
0
def test_value():
    c = Cell('\n| a ')
    assert ' a ' == c.value
    assert repr(c) == 'Cell(\'\\n| a \')'
    assert c.attrs == {}
    # Use _cached_attrs
    assert c.attrs == {}
    # Inline _header cell
    c = Cell('|| 01 ', True)
    assert c.value == ' 01 '
    # Inline non-_header cell
    c = Cell('|| 01 ', False)
    assert c.value == ' 01 '
    # Set a new value
    c.value = '\na\na'
    assert c.value == '\na\na'
示例#13
0
 def test_has_get(self):
     c = Cell('\n! n="v" | 00', True)
     self.assertTrue(c.has_attr('n'))
     self.assertEqual(c.get_attr('n'), 'v')
示例#14
0
def test_has_get():
    c = Cell('\n! n="v" | 00', True)
    assert c.has_attr('n')
    assert c.get_attr('n') == 'v'