import uuid
from nose import SkipTest
from nose.tools import eq_, ok_
from kazoo.testing import KazooTestCase
from kazoo.tests.util import TRAVIS_ZK_VERSION
class KazooQueueTests(KazooTestCase):
def _makeOne(self):
path = "/" + uuid.uuid4().hex
return self.client.Queue(path)
def test_queue_validation(self):
queue = self._makeOne()
self.assertRaises(TypeError, queue.put, {})
self.assertRaises(TypeError, queue.put, b"one", b"100")
self.assertRaises(TypeError, queue.put, b"one", 10.0)
self.assertRaises(ValueError, queue.put, b"one", -100)
self.assertRaises(ValueError, queue.put, b"one", 100000)
def test_empty_queue(self):
queue = self._makeOne()
eq_(len(queue), 0)
self.assertTrue(queue.get() is None)
eq_(len(queue), 0)
def test_queue(self):
queue = self._makeOne()
queue.put(b"one")
queue.put(b"two")
queue.put(b"three")
eq_(len(queue), 3)
eq_(queue.get(), b"one")
eq_(queue.get(), b"two")
eq_(queue.get(), b"three")
eq_(len(queue), 0)
def test_priority(self):
queue = self._makeOne()
queue.put(b"four", priority=101)
queue.put(b"one", priority=0)
queue.put(b"two", priority=0)
queue.put(b"three", priority=10)
eq_(queue.get(), b"one")
eq_(queue.get(), b"two")
eq_(queue.get(), b"three")
eq_(queue.get(), b"four")
class KazooLockingQueueTests(KazooTestCase):
def setUp(self):
KazooTestCase.setUp(self)
skip = False
if TRAVIS_ZK_VERSION and TRAVIS_ZK_VERSION < (3, 4):
skip = True
elif TRAVIS_ZK_VERSION and TRAVIS_ZK_VERSION >= (3, 4):
skip = False
else:
ver = self.client.server_version()
if ver[1] < 4:
skip = True
if skip:
raise SkipTest("Must use Zookeeper 3.4 or above")
def _makeOne(self):
path = "/" + uuid.uuid4().hex
return self.client.LockingQueue(path)
def test_queue_validation(self):
queue = self._makeOne()
self.assertRaises(TypeError, queue.put, {})
self.assertRaises(TypeError, queue.put, b"one", b"100")
self.assertRaises(TypeError, queue.put, b"one", 10.0)
self.assertRaises(ValueError, queue.put, b"one", -100)
self.assertRaises(ValueError, queue.put, b"one", 100000)
self.assertRaises(TypeError, queue.put_all, {})
self.assertRaises(TypeError, queue.put_all, [{}])
self.assertRaises(TypeError, queue.put_all, [b"one"], b"100")
self.assertRaises(TypeError, queue.put_all, [b"one"], 10.0)
self.assertRaises(ValueError, queue.put_all, [b"one"], -100)
self.assertRaises(ValueError, queue.put_all, [b"one"], 100000)
def test_empty_queue(self):
queue = self._makeOne()
eq_(len(queue), 0)
self.assertTrue(queue.get(0) is None)
eq_(len(queue), 0)
def test_queue(self):
queue = self._makeOne()
queue.put(b"one")
queue.put_all([b"two", b"three"])
eq_(len(queue), 3)
ok_(not queue.consume())
ok_(not queue.holds_lock())
eq_(queue.get(1), b"one")
ok_(queue.holds_lock())
# Without consuming, should return the same element
eq_(queue.get(1), b"one")
ok_(queue.consume())
ok_(not queue.holds_lock())
eq_(queue.get(1), b"two")
ok_(queue.holds_lock())
ok_(queue.consume())
ok_(not queue.holds_lock())
eq_(queue.get(1), b"three")
ok_(queue.holds_lock())
ok_(queue.consume())
ok_(not queue.holds_lock())
ok_(not queue.consume())
eq_(len(queue), 0)
def test_consume(self):
queue = self._makeOne()
queue.put(b"one")
ok_(not queue.consume())
queue.get(.1)
ok_(queue.consume())
ok_(not queue.consume())
def test_holds_lock(self):
queue = self._makeOne()
ok_(not queue.holds_lock())
queue.put(b"one")
queue.get(.1)
ok_(queue.holds_lock())
queue.consume()
ok_(not queue.holds_lock())
def test_priority(self):
queue = self._makeOne()
queue.put(b"four", priority=101)
queue.put(b"one", priority=0)
queue.put(b"two", priority=0)
queue.put(b"three", priority=10)
eq_(queue.get(1), b"one")
ok_(queue.consume())
eq_(queue.get(1), b"two")
ok_(queue.consume())
eq_(queue.get(1), b"three")
ok_(queue.consume())
eq_(queue.get(1), b"four")
ok_(queue.consume())
def test_concurrent_execution(self):
queue = self._makeOne()
value1 = []
value2 = []
value3 = []
event1 = self.client.handler.event_object()
event2 = self.client.handler.event_object()
event3 = self.client.handler.event_object()
def get_concurrently(value, event):
q = self.client.LockingQueue(queue.path)
value.append(q.get(.1))
event.set()
self.client.handler.spawn(get_concurrently, value1, event1)
self.client.handler.spawn(get_concurrently, value2, event2)
self.client.handler.spawn(get_concurrently, value3, event3)
queue.put(b"one")
event1.wait(.2)
event2.wait(.2)
event3.wait(.2)
result = value1 + value2 + value3
eq_(result.count(b"one"), 1)
eq_(result.count(None), 2)
#!/usr/bin/env python
#
# Copyright (C) 2013 Google Inc.
#
# This file is part of YouCompleteMe.
#
# YouCompleteMe is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# YouCompleteMe is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from collections import defaultdict
from nose.tools import eq_, ok_
from ycmd.completers import completer_utils as cu
def FiletypeTriggerDictFromSpec_Works_test():
eq_( defaultdict( set, {
'foo': set( [ cu._PrepareTrigger( 'zoo'),
cu._PrepareTrigger( 'bar' ) ] ),
'goo': set( [ cu._PrepareTrigger( 'moo' ) ] ),
'moo': set( [ cu._PrepareTrigger( 'moo' ) ] ),
'qux': set( [ cu._PrepareTrigger( 'q' ) ] )
} ),
cu._FiletypeTriggerDictFromSpec( {
'foo': ['zoo', 'bar'],
'goo,moo': ['moo'],
'qux': ['q']
} ) )
def FiletypeDictUnion_Works_test():
eq_( defaultdict( set, {
'foo': set(['zoo', 'bar', 'maa']),
'goo': set(['moo']),
'bla': set(['boo']),
'qux': set(['q'])
} ),
cu._FiletypeDictUnion( defaultdict( set, {
'foo': set(['zoo', 'bar']),
'goo': set(['moo']),
'qux': set(['q'])
} ), defaultdict( set, {
'foo': set(['maa']),
'bla': set(['boo']),
'qux': set(['q'])
} ) ) )
def MatchesSemanticTrigger_Basic_test():
ok_( not cu._MatchesSemanticTrigger( 'foo.bar', 7, ['.'] ) )
ok_( not cu._MatchesSemanticTrigger( 'foo.bar', 6, ['.'] ) )
ok_( not cu._MatchesSemanticTrigger( 'foo.bar', 5, ['.'] ) )
ok_( cu._MatchesSemanticTrigger( 'foo.bar', 4, ['.'] ) )
ok_( not cu._MatchesSemanticTrigger( 'foo.bar', 3, ['.'] ) )
ok_( not cu._MatchesSemanticTrigger( 'foo.bar', 2, ['.'] ) )
ok_( not cu._MatchesSemanticTrigger( 'foo.bar', 1, ['.'] ) )
ok_( not cu._MatchesSemanticTrigger( 'foo.bar', 0, ['.'] ) )
def MatchesSemanticTrigger_JustTrigger_test():
ok_( cu._MatchesSemanticTrigger( '.', 1, ['.'] ) )
ok_( not cu._MatchesSemanticTrigger( '.', 0, ['.'] ) )
def MatchesSemanticTrigger_TriggerBetweenWords_test():
ok_( cu._MatchesSemanticTrigger( 'foo . bar', 5, ['.'] ) )
def MatchesSemanticTrigger_BadInput_test():
ok_( not cu._MatchesSemanticTrigger( 'foo.bar', 10, ['.'] ) )
ok_( not cu._MatchesSemanticTrigger( 'foo.bar', -1, ['.'] ) )
ok_( not cu._MatchesSemanticTrigger( '', -1, ['.'] ) )
ok_( not cu._MatchesSemanticTrigger( '', 0, ['.'] ) )
ok_( not cu._MatchesSemanticTrigger( '', 1, ['.'] ) )
ok_( not cu._MatchesSemanticTrigger( 'foo.bar', 4, [] ) )
def MatchesSemanticTrigger_TriggerIsWrong_test():
ok_( not cu._MatchesSemanticTrigger( 'foo.bar', 4, [':'] ) )
def MatchesSemanticTrigger_LongerTrigger_test():
ok_( cu._MatchesSemanticTrigger( 'foo::bar', 5, ['::'] ) )
ok_( not cu._MatchesSemanticTrigger( 'foo::bar', 4, ['::'] ) )
def MatchesSemanticTrigger_OneTriggerMatches_test():
ok_( cu._MatchesSemanticTrigger( 'foo::bar', 5, ['.', ';', '::'] ) )
def MatchesSemanticTrigger_RegexTrigger_test():
ok_( cu._MatchesSemanticTrigger( 'foo.bar',
4,
[ cu._PrepareTrigger( r're!\w+\.' ) ] ) )
ok_( not cu._MatchesSemanticTrigger( 'foo . bar',
5,
[ cu._PrepareTrigger( r're!\w+\.' ) ] ) )
def PreparedTriggers_Basic_test():
triggers = cu.PreparedTriggers()
ok_( triggers.MatchesForFiletype( 'foo.bar', 4, 'c' ) )
ok_( triggers.MatchesForFiletype( 'foo->bar', 5, 'cpp' ) )
def PreparedTriggers_OnlySomeFiletypesSelected_test():
triggers = cu.PreparedTriggers( filetype_set = set( 'c' ) )
ok_( triggers.MatchesForFiletype( 'foo.bar', 4, 'c' ) )
ok_( not triggers.MatchesForFiletype( 'foo->bar', 5, 'cpp' ) )
def PreparedTriggers_UserTriggers_test():
triggers = cu.PreparedTriggers( user_trigger_map = { 'c': ['->'] } )
ok_( triggers.MatchesForFiletype( 'foo->bar', 5, 'c' ) )
def PreparedTriggers_ObjectiveC_test():
triggers = cu.PreparedTriggers()
# bracketed calls
ok_( triggers.MatchesForFiletype( '[foo ', 5, 'objc' ) )
ok_( not triggers.MatchesForFiletype( '[foo', 4, 'objc' ) )
ok_( not triggers.MatchesForFiletype( '[3foo ', 6, 'objc' ) )
ok_( triggers.MatchesForFiletype( '[f3oo ', 6, 'objc' ) )
ok_( triggers.MatchesForFiletype( '[[foo ', 6, 'objc' ) )
# bracketless calls
ok_( not triggers.MatchesForFiletype( '3foo ', 5, 'objc' ) )
ok_( triggers.MatchesForFiletype( 'foo3 ', 5, 'objc' ) )
ok_( triggers.MatchesForFiletype( 'foo ', 4, 'objc' ) )
# method composition
ok_( triggers.MatchesForFiletype(
'[NSString stringWithFormat:@"Test %@", stuff] ', 46, 'objc' ) )
ok_( triggers.MatchesForFiletype(
' [NSString stringWithFormat:@"Test"] ', 39, 'objc' ) )
ok_( triggers.MatchesForFiletype(
' [[NSString stringWithFormat:@"Test"] stringByAppendingString:%@] ',
68,
'objc' ) )
ok_( not triggers.MatchesForFiletype( '// foo ', 8, 'objc' ) )
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2013 Google Inc.
#
# This file is part of YouCompleteMe.
#
# YouCompleteMe is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# YouCompleteMe is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from nose.tools import eq_, ok_
from ycmd import identifier_utils as iu
def RemoveIdentifierFreeText_CppComments_test():
eq_( "foo \nbar \nqux",
iu.RemoveIdentifierFreeText(
"foo \nbar //foo \nqux" ) )
def RemoveIdentifierFreeText_PythonComments_test():
eq_( "foo \nbar \nqux",
iu.RemoveIdentifierFreeText(
"foo \nbar #foo \nqux" ) )
def RemoveIdentifierFreeText_CstyleComments_test():
eq_( "foo \nbar \nqux",
iu.RemoveIdentifierFreeText(
"foo \nbar /* foo */\nqux" ) )
eq_( "foo \nbar \nqux",
iu.RemoveIdentifierFreeText(
"foo \nbar /* foo \n foo2 */\nqux" ) )
def RemoveIdentifierFreeText_SimpleSingleQuoteString_test():
eq_( "foo \nbar \nqux",
iu.RemoveIdentifierFreeText(
"foo \nbar 'foo'\nqux" ) )
def RemoveIdentifierFreeText_SimpleDoubleQuoteString_test():
eq_( "foo \nbar \nqux",
iu.RemoveIdentifierFreeText(
'foo \nbar "foo"\nqux' ) )
def RemoveIdentifierFreeText_EscapedQuotes_test():
eq_( "foo \nbar \nqux",
iu.RemoveIdentifierFreeText(
"foo \nbar 'fo\\'oz\\nfoo'\nqux" ) )
eq_( "foo \nbar \nqux",
iu.RemoveIdentifierFreeText(
'foo \nbar "fo\\"oz\\nfoo"\nqux' ) )
def RemoveIdentifierFreeText_SlashesInStrings_test():
eq_( "foo \nbar baz\nqux ",
iu.RemoveIdentifierFreeText(
'foo \nbar "fo\\\\"baz\nqux "qwe"' ) )
eq_( "foo \nbar \nqux ",
iu.RemoveIdentifierFreeText(
"foo '\\\\'\nbar '\\\\'\nqux '\\\\'" ) )
def RemoveIdentifierFreeText_EscapedQuotesStartStrings_test():
eq_( "\\\"foo\\\" zoo",
iu.RemoveIdentifierFreeText(
"\\\"foo\\\"'\"''bar' zoo'test'" ) )
eq_( "\\'foo\\' zoo",
iu.RemoveIdentifierFreeText(
"\\'foo\\'\"'\"\"bar\" zoo\"test\"" ) )
def RemoveIdentifierFreeText_NoMultilineString_test():
eq_( "'\nlet x = \nlet y = ",
iu.RemoveIdentifierFreeText(
"'\nlet x = 'foo'\nlet y = 'bar'" ) )
eq_( "\"\nlet x = \nlet y = ",
iu.RemoveIdentifierFreeText(
"\"\nlet x = \"foo\"\nlet y = \"bar\"" ) )
def RemoveIdentifierFreeText_PythonMultilineString_test():
eq_( "\nzoo",
iu.RemoveIdentifierFreeText(
"\"\"\"\nfoobar\n\"\"\"\nzoo" ) )
eq_( "\nzoo",
iu.RemoveIdentifierFreeText(
"'''\nfoobar\n'''\nzoo" ) )
def ExtractIdentifiersFromText_test():
eq_( [ "foo", "_bar", "BazGoo", "FOO", "_", "x", "one", "two", "moo", "qqq" ],
iu.ExtractIdentifiersFromText(
"foo $_bar \n&BazGoo\n FOO= !!! '-' - _ (x) one-two !moo [qqq]" ) )
def ExtractIdentifiersFromText_Css_test():
eq_( [ "foo", "-zoo", "font-size", "px", "a99" ],
iu.ExtractIdentifiersFromText(
"foo -zoo {font-size: 12px;} a99", "css" ) )
def ExtractIdentifiersFromText_Html_test():
eq_( [ "foo", "goo-foo", "zoo", "bar", "aa", "z", "[email protected]" ],
iu.ExtractIdentifiersFromText(
'<foo> <goo-foo zoo=bar aa="" z=\'\'/> [email protected]', "html" ) )
def IsIdentifier_generic_test():
ok_( iu.IsIdentifier( 'foo' ) )
ok_( iu.IsIdentifier( 'foo129' ) )
ok_( iu.IsIdentifier( 'f12' ) )
ok_( not iu.IsIdentifier( '1foo129' ) )
ok_( not iu.IsIdentifier( '-foo' ) )
ok_( not iu.IsIdentifier( 'foo-' ) )
ok_( not iu.IsIdentifier( 'font-face' ) )
ok_( not iu.IsIdentifier( None ) )
ok_( not iu.IsIdentifier( '' ) )
def IsIdentifier_Css_test():
ok_( iu.IsIdentifier( 'foo' , 'css' ) )
ok_( iu.IsIdentifier( 'a1' , 'css' ) )
ok_( iu.IsIdentifier( 'a-' , 'css' ) )
ok_( iu.IsIdentifier( 'a-b' , 'css' ) )
ok_( iu.IsIdentifier( '_b' , 'css' ) )
ok_( iu.IsIdentifier( '-ms-foo' , 'css' ) )
ok_( iu.IsIdentifier( '-_o' , 'css' ) )
ok_( iu.IsIdentifier( 'font-face', 'css' ) )
ok_( not iu.IsIdentifier( '-3b', 'css' ) )
ok_( not iu.IsIdentifier( '-3' , 'css' ) )
ok_( not iu.IsIdentifier( '3' , 'css' ) )
ok_( not iu.IsIdentifier( 'a' , 'css' ) )
def IsIdentifier_R_test():
ok_( iu.IsIdentifier( 'a' , 'r' ) )
ok_( iu.IsIdentifier( 'a.b' , 'r' ) )
ok_( iu.IsIdentifier( 'a.b.c', 'r' ) )
ok_( iu.IsIdentifier( 'a_b' , 'r' ) )
ok_( iu.IsIdentifier( 'a1' , 'r' ) )
ok_( iu.IsIdentifier( 'a_1' , 'r' ) )
ok_( iu.IsIdentifier( '.a' , 'r' ) )
ok_( iu.IsIdentifier( '.a_b' , 'r' ) )
ok_( iu.IsIdentifier( '.a1' , 'r' ) )
ok_( iu.IsIdentifier( '...' , 'r' ) )
ok_( iu.IsIdentifier( '..1' , 'r' ) )
ok_( not iu.IsIdentifier( '.1a', 'r' ) )
ok_( not iu.IsIdentifier( '.1' , 'r' ) )
ok_( not iu.IsIdentifier( '1a' , 'r' ) )
ok_( not iu.IsIdentifier( '123', 'r' ) )
ok_( not iu.IsIdentifier( '_1a', 'r' ) )
ok_( not iu.IsIdentifier( '_a' , 'r' ) )
def IsIdentifier_Clojure_test():
ok_( iu.IsIdentifier( 'foo' , 'clojure' ) )
ok_( iu.IsIdentifier( 'f9' , 'clojure' ) )
ok_( iu.IsIdentifier( 'a.b.c', 'clojure' ) )
ok_( iu.IsIdentifier( 'a.c' , 'clojure' ) )
ok_( iu.IsIdentifier( 'a/c' , 'clojure' ) )
ok_( iu.IsIdentifier( '*' , 'clojure' ) )
ok_( iu.IsIdentifier( 'a*b' , 'clojure' ) )
ok_( iu.IsIdentifier( '?' , 'clojure' ) )
ok_( iu.IsIdentifier( 'a?b' , 'clojure' ) )
ok_( iu.IsIdentifier( ':' , 'clojure' ) )
ok_( iu.IsIdentifier( 'a:b' , 'clojure' ) )
ok_( iu.IsIdentifier( '+' , 'clojure' ) )
ok_( iu.IsIdentifier( 'a+b' , 'clojure' ) )
ok_( iu.IsIdentifier( '-' , 'clojure' ) )
ok_( iu.IsIdentifier( 'a-b' , 'clojure' ) )
ok_( iu.IsIdentifier( '!' , 'clojure' ) )
ok_( iu.IsIdentifier( 'a!b' , 'clojure' ) )
ok_( not iu.IsIdentifier( '9f' , 'clojure' ) )
ok_( not iu.IsIdentifier( '9' , 'clojure' ) )
ok_( not iu.IsIdentifier( 'a/b/c', 'clojure' ) )
ok_( not iu.IsIdentifier( '(a)' , 'clojure' ) )
def IsIdentifier_Haskell_test():
ok_( iu.IsIdentifier( 'foo' , 'haskell' ) )
ok_( iu.IsIdentifier( "foo'", 'haskell' ) )
ok_( iu.IsIdentifier( "x'" , 'haskell' ) )
ok_( iu.IsIdentifier( "_x'" , 'haskell' ) )
ok_( iu.IsIdentifier( "_x" , 'haskell' ) )
ok_( iu.IsIdentifier( "x9" , 'haskell' ) )
ok_( not iu.IsIdentifier( "'x", 'haskell' ) )
ok_( not iu.IsIdentifier( "9x", 'haskell' ) )
ok_( not iu.IsIdentifier( "9" , 'haskell' ) )
def StartOfLongestIdentifierEndingAtIndex_Simple_test():
eq_( 0, iu.StartOfLongestIdentifierEndingAtIndex( 'foo', 3 ) )
eq_( 0, iu.StartOfLongestIdentifierEndingAtIndex( 'f12', 3 ) )
def StartOfLongestIdentifierEndingAtIndex_BadInput_test():
eq_( 0, iu.StartOfLongestIdentifierEndingAtIndex( '', 0 ) )
eq_( 1, iu.StartOfLongestIdentifierEndingAtIndex( '', 1 ) )
eq_( 5, iu.StartOfLongestIdentifierEndingAtIndex( None, 5 ) )
eq_( -1, iu.StartOfLongestIdentifierEndingAtIndex( 'foo', -1 ) )
eq_( 10, iu.StartOfLongestIdentifierEndingAtIndex( 'foo', 10 ) )
def StartOfLongestIdentifierEndingAtIndex_Punctuation_test():
eq_( 1, iu.StartOfLongestIdentifierEndingAtIndex( '(foo', 4 ) )
eq_( 6, iu.StartOfLongestIdentifierEndingAtIndex( ' foo', 9 ) )
eq_( 4, iu.StartOfLongestIdentifierEndingAtIndex( 'gar;foo', 7 ) )
eq_( 2, iu.StartOfLongestIdentifierEndingAtIndex( '...', 2 ) )
def StartOfLongestIdentifierEndingAtIndex_PunctuationWithUnicode_test():
eq_( 1, iu.StartOfLongestIdentifierEndingAtIndex( u'(fäö', 4 ) )
eq_( 2, iu.StartOfLongestIdentifierEndingAtIndex( u' fäö', 5 ) )
# Not a test, but a test helper function
def LoopExpectLongestIdentifier( ident, expected, end_index ):
eq_( expected, iu.StartOfLongestIdentifierEndingAtIndex( ident, end_index ) )
def StartOfLongestIdentifierEndingAtIndex_Entire_Simple_test():
ident = 'foobar'
for i in range( len( ident ) ):
yield LoopExpectLongestIdentifier, ident, 0, i
def StartOfLongestIdentifierEndingAtIndex_Entire_AllBad_test():
ident = '....'
for i in range( len( ident ) ):
yield LoopExpectLongestIdentifier, ident, i, i
def StartOfLongestIdentifierEndingAtIndex_Entire_FirstCharNotNumber_test():
ident = 'f12341234'
for i in range( len( ident ) ):
yield LoopExpectLongestIdentifier, ident, 0, i
def StartOfLongestIdentifierEndingAtIndex_Entire_SubIdentifierValid_test():
ident = 'f123f1234'
for i in range( len( ident ) ):
yield LoopExpectLongestIdentifier, ident, 0, i
def StartOfLongestIdentifierEndingAtIndex_Entire_Unicode_test():
ident = u'fäöttccoö'
for i in range( len( ident ) ):
yield LoopExpectLongestIdentifier, ident, 0, i
# Not a test, but a test helper function
def LoopExpectIdentfierAtIndex( ident, index, expected ):
eq_( expected, iu.IdentifierAtIndex( ident, index ) )
def IdentifierAtIndex_Entire_Simple_test():
ident = u'foobar'
for i in range( len( ident ) ):
yield LoopExpectIdentfierAtIndex, ident, i, ident
def IdentifierAtIndex_Entire_Unicode_test():
ident = u'fäöttccoö'
for i in range( len( ident ) ):
yield LoopExpectIdentfierAtIndex, ident, i, ident
def IdentifierAtIndex_BadInput_test():
eq_( '', iu.IdentifierAtIndex( '', 0 ) )
eq_( '', iu.IdentifierAtIndex( '', 5 ) )
eq_( '', iu.IdentifierAtIndex( 'foo', 5 ) )
eq_( 'foo', iu.IdentifierAtIndex( 'foo', -5 ) )
def IdentifierAtIndex_IndexPastIdent_test():
eq_( '', iu.IdentifierAtIndex( 'foo ', 5 ) )
def IdentifierAtIndex_StopsAtNonIdentifier_test():
eq_( 'foo', iu.IdentifierAtIndex( 'foo(goo)', 0 ) )
eq_( 'goo', iu.IdentifierAtIndex( 'foo(goo)', 5 ) )
def IdentifierAtIndex_LooksAhead_Success_test():
eq_( 'goo', iu.IdentifierAtIndex( 'foo(goo)', 3 ) )
eq_( 'goo', iu.IdentifierAtIndex( ' goo', 0 ) )
def IdentifierAtIndex_LooksAhead_Failure_test():
eq_( '', iu.IdentifierAtIndex( 'foo ()***()', 5 ) )
def IdentifierAtIndex_SingleCharIdent_test():
eq_( 'f', iu.IdentifierAtIndex( ' f ', 1 ) )
def IdentifierAtIndex_Css_test():
eq_( 'font-face', iu.IdentifierAtIndex( 'font-face', 0, 'css' ) )
Accelerate Your Automation Test Cycles With LambdaTest
Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.