How to use ok_ method in Nose

Best Python code snippet using nose

Run Nose automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

test_queue.py

Source: test_queue.py Github

copy
1import uuid
2
3from nose import SkipTest
4from nose.tools import eq_, ok_
5
6from kazoo.testing import KazooTestCase
7from kazoo.tests.util import TRAVIS_ZK_VERSION
8
9
10class KazooQueueTests(KazooTestCase):
11
12    def _makeOne(self):
13        path = "/" + uuid.uuid4().hex
14        return self.client.Queue(path)
15
16    def test_queue_validation(self):
17        queue = self._makeOne()
18        self.assertRaises(TypeError, queue.put, {})
19        self.assertRaises(TypeError, queue.put, b"one", b"100")
20        self.assertRaises(TypeError, queue.put, b"one", 10.0)
21        self.assertRaises(ValueError, queue.put, b"one", -100)
22        self.assertRaises(ValueError, queue.put, b"one", 100000)
23
24    def test_empty_queue(self):
25        queue = self._makeOne()
26        eq_(len(queue), 0)
27        self.assertTrue(queue.get() is None)
28        eq_(len(queue), 0)
29
30    def test_queue(self):
31        queue = self._makeOne()
32        queue.put(b"one")
33        queue.put(b"two")
34        queue.put(b"three")
35        eq_(len(queue), 3)
36
37        eq_(queue.get(), b"one")
38        eq_(queue.get(), b"two")
39        eq_(queue.get(), b"three")
40        eq_(len(queue), 0)
41
42    def test_priority(self):
43        queue = self._makeOne()
44        queue.put(b"four", priority=101)
45        queue.put(b"one", priority=0)
46        queue.put(b"two", priority=0)
47        queue.put(b"three", priority=10)
48
49        eq_(queue.get(), b"one")
50        eq_(queue.get(), b"two")
51        eq_(queue.get(), b"three")
52        eq_(queue.get(), b"four")
53
54
55class KazooLockingQueueTests(KazooTestCase):
56
57    def setUp(self):
58        KazooTestCase.setUp(self)
59        skip = False
60        if TRAVIS_ZK_VERSION and TRAVIS_ZK_VERSION < (3, 4):
61            skip = True
62        elif TRAVIS_ZK_VERSION and TRAVIS_ZK_VERSION >= (3, 4):
63            skip = False
64        else:
65            ver = self.client.server_version()
66            if ver[1] < 4:
67                skip = True
68        if skip:
69            raise SkipTest("Must use Zookeeper 3.4 or above")
70
71    def _makeOne(self):
72        path = "/" + uuid.uuid4().hex
73        return self.client.LockingQueue(path)
74
75    def test_queue_validation(self):
76        queue = self._makeOne()
77        self.assertRaises(TypeError, queue.put, {})
78        self.assertRaises(TypeError, queue.put, b"one", b"100")
79        self.assertRaises(TypeError, queue.put, b"one", 10.0)
80        self.assertRaises(ValueError, queue.put, b"one", -100)
81        self.assertRaises(ValueError, queue.put, b"one", 100000)
82        self.assertRaises(TypeError, queue.put_all, {})
83        self.assertRaises(TypeError, queue.put_all, [{}])
84        self.assertRaises(TypeError, queue.put_all, [b"one"], b"100")
85        self.assertRaises(TypeError, queue.put_all, [b"one"], 10.0)
86        self.assertRaises(ValueError, queue.put_all, [b"one"], -100)
87        self.assertRaises(ValueError, queue.put_all, [b"one"], 100000)
88
89    def test_empty_queue(self):
90        queue = self._makeOne()
91        eq_(len(queue), 0)
92        self.assertTrue(queue.get(0) is None)
93        eq_(len(queue), 0)
94
95    def test_queue(self):
96        queue = self._makeOne()
97        queue.put(b"one")
98        queue.put_all([b"two", b"three"])
99        eq_(len(queue), 3)
100
101        ok_(not queue.consume())
102        ok_(not queue.holds_lock())
103        eq_(queue.get(1), b"one")
104        ok_(queue.holds_lock())
105        # Without consuming, should return the same element
106        eq_(queue.get(1), b"one")
107        ok_(queue.consume())
108        ok_(not queue.holds_lock())
109        eq_(queue.get(1), b"two")
110        ok_(queue.holds_lock())
111        ok_(queue.consume())
112        ok_(not queue.holds_lock())
113        eq_(queue.get(1), b"three")
114        ok_(queue.holds_lock())
115        ok_(queue.consume())
116        ok_(not queue.holds_lock())
117        ok_(not queue.consume())
118        eq_(len(queue), 0)
119
120    def test_consume(self):
121        queue = self._makeOne()
122
123        queue.put(b"one")
124        ok_(not queue.consume())
125        queue.get(.1)
126        ok_(queue.consume())
127        ok_(not queue.consume())
128
129    def test_holds_lock(self):
130        queue = self._makeOne()
131
132        ok_(not queue.holds_lock())
133        queue.put(b"one")
134        queue.get(.1)
135        ok_(queue.holds_lock())
136        queue.consume()
137        ok_(not queue.holds_lock())
138
139    def test_priority(self):
140        queue = self._makeOne()
141        queue.put(b"four", priority=101)
142        queue.put(b"one", priority=0)
143        queue.put(b"two", priority=0)
144        queue.put(b"three", priority=10)
145
146        eq_(queue.get(1), b"one")
147        ok_(queue.consume())
148        eq_(queue.get(1), b"two")
149        ok_(queue.consume())
150        eq_(queue.get(1), b"three")
151        ok_(queue.consume())
152        eq_(queue.get(1), b"four")
153        ok_(queue.consume())
154
155    def test_concurrent_execution(self):
156        queue = self._makeOne()
157        value1 = []
158        value2 = []
159        value3 = []
160        event1 = self.client.handler.event_object()
161        event2 = self.client.handler.event_object()
162        event3 = self.client.handler.event_object()
163
164        def get_concurrently(value, event):
165            q = self.client.LockingQueue(queue.path)
166            value.append(q.get(.1))
167            event.set()
168
169        self.client.handler.spawn(get_concurrently, value1, event1)
170        self.client.handler.spawn(get_concurrently, value2, event2)
171        self.client.handler.spawn(get_concurrently, value3, event3)
172        queue.put(b"one")
173        event1.wait(.2)
174        event2.wait(.2)
175        event3.wait(.2)
176
177        result = value1 + value2 + value3
178        eq_(result.count(b"one"), 1)
179        eq_(result.count(None), 2)
180
Full Screen

completer_utils_test.py

Source: completer_utils_test.py Github

copy
1#!/usr/bin/env python
2#
3# Copyright (C) 2013  Google Inc.
4#
5# This file is part of YouCompleteMe.
6#
7# YouCompleteMe is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# YouCompleteMe is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with YouCompleteMe.  If not, see <http://www.gnu.org/licenses/>.
19
20from collections import defaultdict
21from nose.tools import eq_, ok_
22from ycmd.completers import completer_utils as cu
23
24
25def FiletypeTriggerDictFromSpec_Works_test():
26  eq_( defaultdict( set, {
27         'foo': set( [ cu._PrepareTrigger( 'zoo'),
28                       cu._PrepareTrigger( 'bar' ) ] ),
29         'goo': set( [ cu._PrepareTrigger( 'moo' ) ] ),
30         'moo': set( [ cu._PrepareTrigger( 'moo' ) ] ),
31         'qux': set( [ cu._PrepareTrigger( 'q' ) ] )
32       } ),
33       cu._FiletypeTriggerDictFromSpec( {
34         'foo': ['zoo', 'bar'],
35         'goo,moo': ['moo'],
36         'qux': ['q']
37       } ) )
38
39
40def FiletypeDictUnion_Works_test():
41  eq_( defaultdict( set, {
42         'foo': set(['zoo', 'bar', 'maa']),
43         'goo': set(['moo']),
44         'bla': set(['boo']),
45         'qux': set(['q'])
46       } ),
47       cu._FiletypeDictUnion( defaultdict( set, {
48         'foo': set(['zoo', 'bar']),
49         'goo': set(['moo']),
50         'qux': set(['q'])
51       } ), defaultdict( set, {
52         'foo': set(['maa']),
53         'bla': set(['boo']),
54         'qux': set(['q'])
55       } ) ) )
56
57
58def MatchesSemanticTrigger_Basic_test():
59  ok_( not cu._MatchesSemanticTrigger( 'foo.bar', 7, ['.'] ) )
60  ok_( not cu._MatchesSemanticTrigger( 'foo.bar', 6, ['.'] ) )
61  ok_( not cu._MatchesSemanticTrigger( 'foo.bar', 5, ['.'] ) )
62
63  ok_( cu._MatchesSemanticTrigger( 'foo.bar', 4, ['.'] ) )
64
65  ok_( not cu._MatchesSemanticTrigger( 'foo.bar', 3, ['.'] ) )
66  ok_( not cu._MatchesSemanticTrigger( 'foo.bar', 2, ['.'] ) )
67  ok_( not cu._MatchesSemanticTrigger( 'foo.bar', 1, ['.'] ) )
68  ok_( not cu._MatchesSemanticTrigger( 'foo.bar', 0, ['.'] ) )
69
70
71def MatchesSemanticTrigger_JustTrigger_test():
72  ok_( cu._MatchesSemanticTrigger( '.', 1, ['.'] ) )
73  ok_( not cu._MatchesSemanticTrigger( '.', 0, ['.'] ) )
74
75
76def MatchesSemanticTrigger_TriggerBetweenWords_test():
77  ok_( cu._MatchesSemanticTrigger( 'foo . bar', 5, ['.'] ) )
78
79
80def MatchesSemanticTrigger_BadInput_test():
81  ok_( not cu._MatchesSemanticTrigger( 'foo.bar', 10, ['.'] ) )
82  ok_( not cu._MatchesSemanticTrigger( 'foo.bar', -1, ['.'] ) )
83  ok_( not cu._MatchesSemanticTrigger( '', -1, ['.'] ) )
84  ok_( not cu._MatchesSemanticTrigger( '', 0, ['.'] ) )
85  ok_( not cu._MatchesSemanticTrigger( '', 1, ['.'] ) )
86  ok_( not cu._MatchesSemanticTrigger( 'foo.bar', 4, [] ) )
87
88
89def MatchesSemanticTrigger_TriggerIsWrong_test():
90  ok_( not cu._MatchesSemanticTrigger( 'foo.bar', 4, [':'] ) )
91
92
93def MatchesSemanticTrigger_LongerTrigger_test():
94  ok_( cu._MatchesSemanticTrigger( 'foo::bar', 5, ['::'] ) )
95  ok_( not cu._MatchesSemanticTrigger( 'foo::bar', 4, ['::'] ) )
96
97
98def MatchesSemanticTrigger_OneTriggerMatches_test():
99  ok_( cu._MatchesSemanticTrigger( 'foo::bar', 5, ['.', ';', '::'] ) )
100
101
102def MatchesSemanticTrigger_RegexTrigger_test():
103  ok_( cu._MatchesSemanticTrigger( 'foo.bar',
104                                   4,
105                                   [ cu._PrepareTrigger( r're!\w+\.' ) ] ) )
106
107  ok_( not cu._MatchesSemanticTrigger( 'foo . bar',
108                                       5,
109                                       [ cu._PrepareTrigger( r're!\w+\.' ) ] ) )
110
111
112def PreparedTriggers_Basic_test():
113  triggers = cu.PreparedTriggers()
114  ok_( triggers.MatchesForFiletype( 'foo.bar', 4, 'c' ) )
115  ok_( triggers.MatchesForFiletype( 'foo->bar', 5, 'cpp' ) )
116
117
118def PreparedTriggers_OnlySomeFiletypesSelected_test():
119  triggers = cu.PreparedTriggers( filetype_set = set( 'c' ) )
120  ok_( triggers.MatchesForFiletype( 'foo.bar', 4, 'c' ) )
121  ok_( not triggers.MatchesForFiletype( 'foo->bar', 5, 'cpp' ) )
122
123
124def PreparedTriggers_UserTriggers_test():
125  triggers = cu.PreparedTriggers( user_trigger_map = { 'c': ['->'] } )
126  ok_( triggers.MatchesForFiletype( 'foo->bar', 5, 'c' ) )
127
128
129def PreparedTriggers_ObjectiveC_test():
130  triggers = cu.PreparedTriggers()
131  # bracketed calls
132  ok_( triggers.MatchesForFiletype( '[foo ', 5, 'objc' ) )
133  ok_( not triggers.MatchesForFiletype( '[foo', 4, 'objc' ) )
134  ok_( not triggers.MatchesForFiletype( '[3foo ', 6, 'objc' ) )
135  ok_( triggers.MatchesForFiletype( '[f3oo ', 6, 'objc' ) )
136  ok_( triggers.MatchesForFiletype( '[[foo ', 6, 'objc' ) )
137
138  # bracketless calls
139  ok_( not triggers.MatchesForFiletype( '3foo ', 5, 'objc' ) )
140  ok_( triggers.MatchesForFiletype( 'foo3 ', 5, 'objc' ) )
141  ok_( triggers.MatchesForFiletype( 'foo ', 4, 'objc' ) )
142
143  # method composition
144  ok_( triggers.MatchesForFiletype(
145      '[NSString stringWithFormat:@"Test %@", stuff] ', 46, 'objc' ) )
146  ok_( triggers.MatchesForFiletype(
147      '   [NSString stringWithFormat:@"Test"] ', 39, 'objc' ) )
148  ok_( triggers.MatchesForFiletype(
149      '   [[NSString stringWithFormat:@"Test"] stringByAppendingString:%@] ',
150      68,
151      'objc' ) )
152
153  ok_( not triggers.MatchesForFiletype( '// foo ', 8, 'objc' ) )
154
155
Full Screen

identifier_utils_test.py

Source: identifier_utils_test.py Github

copy
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Copyright (C) 2013  Google Inc.
5#
6# This file is part of YouCompleteMe.
7#
8# YouCompleteMe is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# YouCompleteMe is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with YouCompleteMe.  If not, see <http://www.gnu.org/licenses/>.
20
21from nose.tools import eq_, ok_
22from ycmd import identifier_utils as iu
23
24
25def RemoveIdentifierFreeText_CppComments_test():
26  eq_( "foo \nbar \nqux",
27       iu.RemoveIdentifierFreeText(
28          "foo \nbar //foo \nqux" ) )
29
30
31def RemoveIdentifierFreeText_PythonComments_test():
32  eq_( "foo \nbar \nqux",
33       iu.RemoveIdentifierFreeText(
34          "foo \nbar #foo \nqux" ) )
35
36
37def RemoveIdentifierFreeText_CstyleComments_test():
38  eq_( "foo \nbar \nqux",
39       iu.RemoveIdentifierFreeText(
40          "foo \nbar /* foo */\nqux" ) )
41
42  eq_( "foo \nbar \nqux",
43       iu.RemoveIdentifierFreeText(
44          "foo \nbar /* foo \n foo2 */\nqux" ) )
45
46
47def RemoveIdentifierFreeText_SimpleSingleQuoteString_test():
48  eq_( "foo \nbar \nqux",
49       iu.RemoveIdentifierFreeText(
50          "foo \nbar 'foo'\nqux" ) )
51
52
53def RemoveIdentifierFreeText_SimpleDoubleQuoteString_test():
54  eq_( "foo \nbar \nqux",
55       iu.RemoveIdentifierFreeText(
56          'foo \nbar "foo"\nqux' ) )
57
58
59def RemoveIdentifierFreeText_EscapedQuotes_test():
60  eq_( "foo \nbar \nqux",
61       iu.RemoveIdentifierFreeText(
62          "foo \nbar 'fo\\'oz\\nfoo'\nqux" ) )
63
64  eq_( "foo \nbar \nqux",
65       iu.RemoveIdentifierFreeText(
66          'foo \nbar "fo\\"oz\\nfoo"\nqux' ) )
67
68
69def RemoveIdentifierFreeText_SlashesInStrings_test():
70  eq_( "foo \nbar baz\nqux ",
71       iu.RemoveIdentifierFreeText(
72           'foo \nbar "fo\\\\"baz\nqux "qwe"' ) )
73
74  eq_( "foo \nbar \nqux ",
75       iu.RemoveIdentifierFreeText(
76           "foo '\\\\'\nbar '\\\\'\nqux '\\\\'" ) )
77
78
79def RemoveIdentifierFreeText_EscapedQuotesStartStrings_test():
80  eq_( "\\\"foo\\\" zoo",
81       iu.RemoveIdentifierFreeText(
82           "\\\"foo\\\"'\"''bar' zoo'test'" ) )
83
84  eq_( "\\'foo\\' zoo",
85       iu.RemoveIdentifierFreeText(
86           "\\'foo\\'\"'\"\"bar\" zoo\"test\"" ) )
87
88
89def RemoveIdentifierFreeText_NoMultilineString_test():
90  eq_( "'\nlet x = \nlet y = ",
91       iu.RemoveIdentifierFreeText(
92           "'\nlet x = 'foo'\nlet y = 'bar'" ) )
93
94  eq_( "\"\nlet x = \nlet y = ",
95       iu.RemoveIdentifierFreeText(
96           "\"\nlet x = \"foo\"\nlet y = \"bar\"" ) )
97
98
99def RemoveIdentifierFreeText_PythonMultilineString_test():
100  eq_( "\nzoo",
101       iu.RemoveIdentifierFreeText(
102           "\"\"\"\nfoobar\n\"\"\"\nzoo" ) )
103
104  eq_( "\nzoo",
105       iu.RemoveIdentifierFreeText(
106           "'''\nfoobar\n'''\nzoo" ) )
107
108
109def ExtractIdentifiersFromText_test():
110  eq_( [ "foo", "_bar", "BazGoo", "FOO", "_", "x", "one", "two", "moo", "qqq" ],
111       iu.ExtractIdentifiersFromText(
112           "foo $_bar \n&BazGoo\n FOO= !!! '-' - _ (x) one-two !moo [qqq]" ) )
113
114
115def ExtractIdentifiersFromText_Css_test():
116  eq_( [ "foo", "-zoo", "font-size", "px", "a99" ],
117       iu.ExtractIdentifiersFromText(
118           "foo -zoo {font-size: 12px;} a99", "css" ) )
119
120
121def ExtractIdentifiersFromText_Html_test():
122  eq_( [ "foo", "goo-foo", "zoo", "bar", "aa", "z", "[email protected]" ],
123       iu.ExtractIdentifiersFromText(
124           '<foo> <goo-foo zoo=bar aa="" z=\'\'/> [email protected]', "html" ) )
125
126
127def IsIdentifier_generic_test():
128  ok_( iu.IsIdentifier( 'foo' ) )
129  ok_( iu.IsIdentifier( 'foo129' ) )
130  ok_( iu.IsIdentifier( 'f12' ) )
131
132  ok_( not iu.IsIdentifier( '1foo129' ) )
133  ok_( not iu.IsIdentifier( '-foo' ) )
134  ok_( not iu.IsIdentifier( 'foo-' ) )
135  ok_( not iu.IsIdentifier( 'font-face' ) )
136  ok_( not iu.IsIdentifier( None ) )
137  ok_( not iu.IsIdentifier( '' ) )
138
139
140def IsIdentifier_Css_test():
141  ok_( iu.IsIdentifier( 'foo'      , 'css' ) )
142  ok_( iu.IsIdentifier( 'a1'       , 'css' ) )
143  ok_( iu.IsIdentifier( 'a-'       , 'css' ) )
144  ok_( iu.IsIdentifier( 'a-b'      , 'css' ) )
145  ok_( iu.IsIdentifier( '_b'       , 'css' ) )
146  ok_( iu.IsIdentifier( '-ms-foo'  , 'css' ) )
147  ok_( iu.IsIdentifier( '-_o'      , 'css' ) )
148  ok_( iu.IsIdentifier( 'font-face', 'css' ) )
149
150  ok_( not iu.IsIdentifier( '-3b', 'css' ) )
151  ok_( not iu.IsIdentifier( '-3' , 'css' ) )
152  ok_( not iu.IsIdentifier( '3'  , 'css' ) )
153  ok_( not iu.IsIdentifier( 'a'  , 'css' ) )
154
155
156def IsIdentifier_R_test():
157  ok_( iu.IsIdentifier( 'a'    , 'r' ) )
158  ok_( iu.IsIdentifier( 'a.b'  , 'r' ) )
159  ok_( iu.IsIdentifier( 'a.b.c', 'r' ) )
160  ok_( iu.IsIdentifier( 'a_b'  , 'r' ) )
161  ok_( iu.IsIdentifier( 'a1'   , 'r' ) )
162  ok_( iu.IsIdentifier( 'a_1'  , 'r' ) )
163  ok_( iu.IsIdentifier( '.a'   , 'r' ) )
164  ok_( iu.IsIdentifier( '.a_b' , 'r' ) )
165  ok_( iu.IsIdentifier( '.a1'  , 'r' ) )
166  ok_( iu.IsIdentifier( '...'  , 'r' ) )
167  ok_( iu.IsIdentifier( '..1'  , 'r' ) )
168
169  ok_( not iu.IsIdentifier( '.1a', 'r' ) )
170  ok_( not iu.IsIdentifier( '.1' , 'r' ) )
171  ok_( not iu.IsIdentifier( '1a' , 'r' ) )
172  ok_( not iu.IsIdentifier( '123', 'r' ) )
173  ok_( not iu.IsIdentifier( '_1a', 'r' ) )
174  ok_( not iu.IsIdentifier( '_a' , 'r' ) )
175
176
177def IsIdentifier_Clojure_test():
178  ok_( iu.IsIdentifier( 'foo'  , 'clojure' ) )
179  ok_( iu.IsIdentifier( 'f9'   , 'clojure' ) )
180  ok_( iu.IsIdentifier( 'a.b.c', 'clojure' ) )
181  ok_( iu.IsIdentifier( 'a.c'  , 'clojure' ) )
182  ok_( iu.IsIdentifier( 'a/c'  , 'clojure' ) )
183  ok_( iu.IsIdentifier( '*'    , 'clojure' ) )
184  ok_( iu.IsIdentifier( 'a*b'  , 'clojure' ) )
185  ok_( iu.IsIdentifier( '?'    , 'clojure' ) )
186  ok_( iu.IsIdentifier( 'a?b'  , 'clojure' ) )
187  ok_( iu.IsIdentifier( ':'    , 'clojure' ) )
188  ok_( iu.IsIdentifier( 'a:b'  , 'clojure' ) )
189  ok_( iu.IsIdentifier( '+'    , 'clojure' ) )
190  ok_( iu.IsIdentifier( 'a+b'  , 'clojure' ) )
191  ok_( iu.IsIdentifier( '-'    , 'clojure' ) )
192  ok_( iu.IsIdentifier( 'a-b'  , 'clojure' ) )
193  ok_( iu.IsIdentifier( '!'    , 'clojure' ) )
194  ok_( iu.IsIdentifier( 'a!b'  , 'clojure' ) )
195
196  ok_( not iu.IsIdentifier( '9f'   , 'clojure' ) )
197  ok_( not iu.IsIdentifier( '9'    , 'clojure' ) )
198  ok_( not iu.IsIdentifier( 'a/b/c', 'clojure' ) )
199  ok_( not iu.IsIdentifier( '(a)'  , 'clojure' ) )
200
201
202def IsIdentifier_Haskell_test():
203  ok_( iu.IsIdentifier( 'foo' , 'haskell' ) )
204  ok_( iu.IsIdentifier( "foo'", 'haskell' ) )
205  ok_( iu.IsIdentifier( "x'"  , 'haskell' ) )
206  ok_( iu.IsIdentifier( "_x'" , 'haskell' ) )
207  ok_( iu.IsIdentifier( "_x"  , 'haskell' ) )
208  ok_( iu.IsIdentifier( "x9"  , 'haskell' ) )
209
210  ok_( not iu.IsIdentifier( "'x", 'haskell' ) )
211  ok_( not iu.IsIdentifier( "9x", 'haskell' ) )
212  ok_( not iu.IsIdentifier( "9" , 'haskell' ) )
213
214
215def StartOfLongestIdentifierEndingAtIndex_Simple_test():
216  eq_( 0, iu.StartOfLongestIdentifierEndingAtIndex( 'foo', 3 ) )
217  eq_( 0, iu.StartOfLongestIdentifierEndingAtIndex( 'f12', 3 ) )
218
219
220def StartOfLongestIdentifierEndingAtIndex_BadInput_test():
221  eq_( 0, iu.StartOfLongestIdentifierEndingAtIndex( '', 0 ) )
222  eq_( 1, iu.StartOfLongestIdentifierEndingAtIndex( '', 1 ) )
223  eq_( 5, iu.StartOfLongestIdentifierEndingAtIndex( None, 5 ) )
224  eq_( -1, iu.StartOfLongestIdentifierEndingAtIndex( 'foo', -1 ) )
225  eq_( 10, iu.StartOfLongestIdentifierEndingAtIndex( 'foo', 10 ) )
226
227
228def StartOfLongestIdentifierEndingAtIndex_Punctuation_test():
229  eq_( 1, iu.StartOfLongestIdentifierEndingAtIndex( '(foo', 4 ) )
230  eq_( 6, iu.StartOfLongestIdentifierEndingAtIndex( '      foo', 9 ) )
231  eq_( 4, iu.StartOfLongestIdentifierEndingAtIndex( 'gar;foo', 7 ) )
232  eq_( 2, iu.StartOfLongestIdentifierEndingAtIndex( '...', 2 ) )
233
234
235def StartOfLongestIdentifierEndingAtIndex_PunctuationWithUnicode_test():
236  eq_( 1, iu.StartOfLongestIdentifierEndingAtIndex( u'(fäö', 4 ) )
237  eq_( 2, iu.StartOfLongestIdentifierEndingAtIndex( u'  fäö', 5 ) )
238
239
240# Not a test, but a test helper function
241def LoopExpectLongestIdentifier( ident, expected, end_index ):
242  eq_( expected, iu.StartOfLongestIdentifierEndingAtIndex( ident, end_index ) )
243
244
245def StartOfLongestIdentifierEndingAtIndex_Entire_Simple_test():
246  ident = 'foobar'
247  for i in range( len( ident ) ):
248    yield LoopExpectLongestIdentifier, ident, 0, i
249
250
251def StartOfLongestIdentifierEndingAtIndex_Entire_AllBad_test():
252  ident = '....'
253  for i in range( len( ident ) ):
254    yield LoopExpectLongestIdentifier, ident, i, i
255
256
257def StartOfLongestIdentifierEndingAtIndex_Entire_FirstCharNotNumber_test():
258  ident = 'f12341234'
259  for i in range( len( ident ) ):
260    yield LoopExpectLongestIdentifier, ident, 0, i
261
262
263def StartOfLongestIdentifierEndingAtIndex_Entire_SubIdentifierValid_test():
264  ident = 'f123f1234'
265  for i in range( len( ident ) ):
266    yield LoopExpectLongestIdentifier, ident, 0, i
267
268
269def StartOfLongestIdentifierEndingAtIndex_Entire_Unicode_test():
270  ident = u'fäöttccoö'
271  for i in range( len( ident ) ):
272    yield LoopExpectLongestIdentifier, ident, 0, i
273
274
275# Not a test, but a test helper function
276def LoopExpectIdentfierAtIndex( ident, index, expected ):
277  eq_( expected, iu.IdentifierAtIndex( ident, index ) )
278
279
280def IdentifierAtIndex_Entire_Simple_test():
281  ident = u'foobar'
282  for i in range( len( ident ) ):
283    yield LoopExpectIdentfierAtIndex, ident, i, ident
284
285
286def IdentifierAtIndex_Entire_Unicode_test():
287  ident = u'fäöttccoö'
288  for i in range( len( ident ) ):
289    yield LoopExpectIdentfierAtIndex, ident, i, ident
290
291
292def IdentifierAtIndex_BadInput_test():
293  eq_( '', iu.IdentifierAtIndex( '', 0 ) )
294  eq_( '', iu.IdentifierAtIndex( '', 5 ) )
295  eq_( '', iu.IdentifierAtIndex( 'foo', 5 ) )
296  eq_( 'foo', iu.IdentifierAtIndex( 'foo', -5 ) )
297
298
299def IdentifierAtIndex_IndexPastIdent_test():
300  eq_( '', iu.IdentifierAtIndex( 'foo    ', 5 ) )
301
302
303def IdentifierAtIndex_StopsAtNonIdentifier_test():
304  eq_( 'foo', iu.IdentifierAtIndex( 'foo(goo)', 0 ) )
305  eq_( 'goo', iu.IdentifierAtIndex( 'foo(goo)', 5 ) )
306
307
308def IdentifierAtIndex_LooksAhead_Success_test():
309  eq_( 'goo', iu.IdentifierAtIndex( 'foo(goo)', 3 ) )
310  eq_( 'goo', iu.IdentifierAtIndex( '   goo', 0 ) )
311
312
313def IdentifierAtIndex_LooksAhead_Failure_test():
314  eq_( '', iu.IdentifierAtIndex( 'foo    ()***()', 5 ) )
315
316
317def IdentifierAtIndex_SingleCharIdent_test():
318  eq_( 'f', iu.IdentifierAtIndex( '    f    ', 1 ) )
319
320
321def IdentifierAtIndex_Css_test():
322  eq_( 'font-face', iu.IdentifierAtIndex( 'font-face', 0, 'css' ) )
323
Full Screen

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.

Try LambdaTest

Run Python Tests on LambdaTest Cloud Grid

Execute automation tests with Nose on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)