How to use somefunc 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_message.py

Source: test_message.py Github

copy
1from unittest import TestCase
2from prospector.message import Location
3
4
5class LocationOrderTest(TestCase):
6
7    def test_path_order(self):
8
9        locs = [
10            Location('/tmp/path/module3.py', 'module3', 'somefunc', 15, 0),
11            Location('/tmp/path/module1.py', 'module1', 'somefunc', 10, 0),
12            Location('/tmp/path/module2.py', 'module2', 'somefunc', 9, 0)
13        ]
14
15        paths = [loc.path for loc in locs]
16        expected = sorted(paths)
17
18        self.assertEqual(expected, [loc.path for loc in sorted(locs)])
19
20    def test_line_order(self):
21
22        locs = [
23            Location('/tmp/path/module1.py', 'module1', 'somefunc', 15, 0),
24            Location('/tmp/path/module1.py', 'module1', 'somefunc', 10, 0),
25            Location('/tmp/path/module1.py', 'module1', 'somefunc', 12, 0)
26        ]
27
28        lines = [loc.line for loc in locs]
29        expected = sorted(lines)
30
31        self.assertEqual(expected, [loc.line for loc in sorted(locs)])
32
33    def test_sort_between_none_lines(self):
34
35        locs = [
36            Location('/tmp/path/module1.py', 'module1', 'somefunc', 15, 0),
37            Location('/tmp/path/module1.py', 'module1', 'somefunc', 10, 0),
38            Location('/tmp/path/module1.py', 'module1', 'somefunc', -1, 0)
39        ]
40
41        lines = [(loc.line or -1) for loc in locs]
42        expected = [None if l == -1 else l for l in sorted(lines)]
43
44        self.assertEqual(expected, [loc.line for loc in sorted(locs)])
45
46    def test_char_order(self):
47
48        locs = [
49            Location('/tmp/path/module1.py', 'module1', 'somefunc', 10, 7),
50            Location('/tmp/path/module1.py', 'module1', 'somefunc', 10, 0),
51            Location('/tmp/path/module1.py', 'module1', 'somefunc', 10, 2)
52        ]
53
54        chars = [loc.character for loc in locs]
55        expected = sorted(chars)
56
57        self.assertEqual(expected, [loc.character for loc in sorted(locs)])
58
59    def test_sort_between_none_chars(self):
60
61        locs = [
62            Location('/tmp/path/module1.py', 'module1', 'somefunc', 10, -1),
63            Location('/tmp/path/module1.py', 'module1', 'somefunc', 10, 1),
64            Location('/tmp/path/module1.py', 'module1', 'somefunc', 10, 2)
65        ]
66
67        chars = [(loc.character or -1) for loc in locs]
68        expected = [None if c == -1 else c for c in sorted(chars)]
69
70        self.assertEqual(expected, [loc.character for loc in sorted(locs)])
71
Full Screen

test_Scheduler.py

Source: test_Scheduler.py Github

copy
1#!/usr/bin/env python
2#
3#   Copyright (c) 2016 In-Q-Tel, Inc, All Rights Reserved.
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16"""
17Test module for Onos.py
18
19Created on 28 June 2016
20@author: dgrossman
21"""
22import logging
23import logging.config
24
25import pytest
26
27from poseidon.baseClasses.enums_tuples import CRONSPEC
28from poseidon.baseClasses.enums_tuples import EVERY
29from poseidon.poseidonMain.Scheduler.Scheduler import Scheduler
30from poseidon.poseidonMain.Scheduler.Scheduler import scheduler_interface
31
32
33module_logger = logging.getLogger(__name__)
34
35
36def test_instantiation():
37    Scheduler()
38
39
40def somefunc(jobId, logger):
41    module_logger.info('someFunc: {0} {1}'.format(jobId, str(logger)))
42    return True
43
44
45def test_add():
46
47    jobId = 'JOBID'
48    jobId2 = 'JOBID2'
49
50    s = scheduler_interface
51    s.logger = module_logger
52    s.logger.setLevel(logging.DEBUG)
53
54    b = CRONSPEC(EVERY.minute, None)
55    ostr = 'cronspec: {0}'.format(str(b))
56    module_logger.debug(ostr)
57
58    s.add_job(jobId, b, somefunc)
59    s.add_job(jobId2, b, somefunc)
60
61    s.schedule.run_all()
62
63    assert len(s.schedule.jobs) == 2
64    s.shutdown()
65
66
67def test_remove():
68    jobId = 'JOBID'
69    jobId2 = 'JOBID2'
70
71    s = scheduler_interface
72    s.logger = module_logger
73    s.logger.setLevel(logging.DEBUG)
74
75    b = CRONSPEC(EVERY.minute, None)
76
77    ostr = 'jobs:{0}'.format(len(s.schedule.jobs))
78    module_logger.info(ostr)
79
80    s.add_job(jobId, b, somefunc)
81    s.add_job(jobId2, b, somefunc)
82
83    s.schedule.run_all()
84
85    assert len(s.schedule.jobs) == 2
86
87    s.del_job(jobId)
88
89    assert len(s.schedule.jobs) == 1
90
91    s.del_job(jobId2)
92
93    assert len(s.schedule.jobs) == 0
94    s.shutdown()
95
96
97def test_schedule_once():
98    jobId = 'JOBID'
99    jobId2 = 'JOBID2'
100
101    s = scheduler_interface
102    s.logger = module_logger
103    s.logger.setLevel(logging.DEBUG)
104
105    b = CRONSPEC(EVERY.once, '00:00')
106    c = CRONSPEC(EVERY.once, None)
107
108    module_logger.info('jobs:{0}'.format(len(s.schedule.jobs)))
109
110    s.add_job(jobId, b, somefunc)
111    assert len(s.schedule.jobs) == 1
112
113    module_logger.info('run')
114    s.schedule.run_all()
115    assert len(s.schedule.jobs) == 0
116
117    s.add_job(jobId2, c, somefunc)
118    assert len(s.schedule.jobs) == 1
119    module_logger.info('run')
120    s.schedule.run_all()
121    assert len(s.schedule.jobs) == 0
122    s.shutdown()
123
124
125def test_schedule_day():
126    jobId = 'JOBID'
127    jobId2 = 'JOBID2'
128
129    s = scheduler_interface
130    s.logger = module_logger
131    s.logger.setLevel(logging.DEBUG)
132
133    b = CRONSPEC(EVERY.day, '00:00')
134    c = CRONSPEC(EVERY.day, None)
135
136    module_logger.info('day jobs:{0}'.format(len(s.schedule.jobs)))
137
138    s.add_job(jobId, b, somefunc)
139    s.add_job(jobId2, c, somefunc)
140
141    assert len(s.schedule.jobs) == 2
142
143    s.schedule.run_all()
144
145    assert len(s.schedule.jobs) == 2
146
147    s.del_job(jobId)
148
149    assert len(s.schedule.jobs) == 1
150
151    s.del_job(jobId2)
152
153    assert len(s.schedule.jobs) == 0
154    s.shutdown()
155
156
157def test_schedule_hour():
158    jobId = 'JOBID'
159    jobId2 = 'JOBID2'
160
161    s = scheduler_interface
162    s.logger = module_logger
163    s.logger.setLevel(logging.DEBUG)
164
165    b = CRONSPEC(EVERY.hour, ':00')
166    c = CRONSPEC(EVERY.hour, None)
167
168    module_logger.info('jobs:{0}'.format(len(s.schedule.jobs)))
169
170    s.add_job(jobId, b, somefunc)
171    s.add_job(jobId2, c, somefunc)
172
173    ostr = 'xx' * 20 + '{0}'.format(s.list_jobs())
174    module_logger.info(ostr)
175    assert len(s.schedule.jobs) == 2
176    assert len(s.list_jobs().values()) == 2
177
178    s.schedule.run_all()
179
180    assert len(s.schedule.jobs) == 2
181
182    s.del_job(jobId)
183
184    assert len(s.schedule.jobs) == 1
185
186    s.del_job(jobId2)
187
188    assert len(s.schedule.jobs) == 0
189    s.shutdown()
190
191
192def test_schedule_minute():
193    jobId = 'JOBID'
194    jobId2 = 'JOBID2'
195
196    s = scheduler_interface
197    s.logger = module_logger
198    s.logger.setLevel(logging.DEBUG)
199
200    b = CRONSPEC(EVERY.minute, None)
201    c = CRONSPEC(EVERY.minute, 5)
202
203    module_logger.info('cronspec:{0}'.format(str(b)))
204
205    s.add_job(jobId, b, somefunc)
206    s.add_job(jobId2, c, somefunc)
207
208    s.schedule.run_all()
209
210    assert len(s.schedule.jobs) == 2
211
212    s.del_job(jobId)
213
214    assert len(s.schedule.jobs) == 1
215
216    s.del_job(jobId2)
217
218    assert len(s.schedule.jobs) == 0
219    s.shutdown()
220
Full Screen

rave_pgf_registry_test.py

Source: rave_pgf_registry_test.py Github

copy
1'''
2Copyright (C) 2018 Swedish Meteorological and Hydrological Institute, SMHI,
3
4This file is part of RAVE.
5
6RAVE is free software: you can redistribute it and/or modify
7it under the terms of the GNU Lesser General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11RAVE is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14GNU Lesser General Public License for more details.
15
16You should have received a copy of the GNU Lesser General Public License
17along with RAVE.  If not, see <http://www.gnu.org/licenses/>.
18------------------------------------------------------------------------*/
19
20Tests the python version of the pgf registry xml handling
21
22@file
23@author Anders Henja (Swedish Meteorological and Hydrological Institute, SMHI)
24@date 2018-03-10
25'''
26import unittest
27import string
28import os
29import rave_pgf_registry
30
31class rave_pgf_registry_test(unittest.TestCase):
32  TEMPORARY_FILE="rave_pgf_registry_test.xml"
33  
34  def setUp(self):
35    if os.path.isfile(self.TEMPORARY_FILE):
36      os.unlink(self.TEMPORARY_FILE)
37
38  def tearDown(self):
39    if os.path.isfile(self.TEMPORARY_FILE):
40      os.unlink(self.TEMPORARY_FILE)
41
42  def testRead(self):
43    txt = """<?xml version="1.0" encoding="UTF-8"?>
44<generate-registry>
45  <se.somefunc.1 function="generate" help="help text" module="rave_plugin">
46    <arguments floats="zra,zrb" ints="a,b,c" strings="str" />
47  </se.somefunc.1>
48  <se.somefunc.2 function="generate2" help="help text2" module="rave_plugin2">
49    <arguments floats="zraz,zrbz" ints="az,bz,cz" strings="strz" />
50  </se.somefunc.2>
51</generate-registry>
52"""    
53    self.writeTempFile(txt)
54    
55    classUnderTest = rave_pgf_registry.PGF_Registry()
56    classUnderTest.read(self.TEMPORARY_FILE)
57    self.assertEqual(txt, classUnderTest.tostring())
58    
59    el = classUnderTest.find("se.somefunc.1")
60    self.assertTrue(el != None)
61    self.assertEqual("generate", el.attrib["function"])
62    self.assertEqual("rave_plugin", el.attrib["module"])
63    self.assertEqual("help text", el.attrib["help"])
64    self.assertEqual("zra,zrb", el[0].attrib["floats"])
65    self.assertEqual("a,b,c", el[0].attrib["ints"])
66    self.assertEqual("str", el[0].attrib["strings"])
67    
68    el = classUnderTest.find("se.somefunc.2")
69    self.assertTrue(el != None)
70    self.assertEqual("generate2", el.attrib["function"])
71    self.assertEqual("rave_plugin2", el.attrib["module"])
72    self.assertEqual("help text2", el.attrib["help"])
73    self.assertEqual("zraz,zrbz", el[0].attrib["floats"])
74    self.assertEqual("az,bz,cz", el[0].attrib["ints"])
75    self.assertEqual("strz", el[0].attrib["strings"])
76    
77  def testRegister(self):
78    txt = """<?xml version="1.0" encoding="UTF-8"?>
79<generate-registry>
80  <se.somefunc.1 function="generate" help="help text" module="rave_plugin">
81    <arguments floats="zra,zrb" ints="a,b,c" strings="str" />
82  </se.somefunc.1>
83  <se.somefunc.2 function="generate2" help="help text2" module="rave_plugin2">
84    <arguments floats="zraz,zrbz" ints="az,bz,cz" strings="strz" />
85  </se.somefunc.2>
86</generate-registry>
87"""    
88
89    expected = """<?xml version="1.0" encoding="UTF-8"?>
90<generate-registry>
91  <se.somefunc.1 function="generate" help="help text" module="rave_plugin">
92    <arguments floats="zra,zrb" ints="a,b,c" strings="str" />
93  </se.somefunc.1>
94  <se.somefunc.2 function="generate2" help="help text2" module="rave_plugin2">
95    <arguments floats="zraz,zrbz" ints="az,bz,cz" strings="strz" />
96  </se.somefunc.2>
97  <se.somefunc.3 function="generate3" help="help text3" module="rave_plugin3">
98    <arguments floats="f1" ints="i1" strings="s1" />
99  </se.somefunc.3>
100</generate-registry>
101"""    
102
103
104    self.writeTempFile(txt)
105    
106    classUnderTest = rave_pgf_registry.PGF_Registry(filename=self.TEMPORARY_FILE)
107
108    classUnderTest.register("se.somefunc.3", "rave_plugin3", "generate3", "help text3", "s1", "i1", "f1", "")
109
110    with open(self.TEMPORARY_FILE) as fp:
111      result = fp.read()
112    
113    self.assertEqual(expected, result)
114
115
116  def writeTempFile(self, txt):
117    if os.path.isfile(self.TEMPORARY_FILE):
118      os.unlink(self.TEMPORARY_FILE)
119    fp = open(self.TEMPORARY_FILE, "w")
120    fp.write(txt)
121    fp.close()
122
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)