Browse Source

remove nose

Guénaël Muller 7 years ago
parent
commit
8a642acee6

+ 0 - 1
setup.py View File

@@ -32,7 +32,6 @@ tests_require = [
32 32
     'WebTest >= 1.3.1',  # py3 compat
33 33
     'pytest',
34 34
     'pytest-cov',
35
-    'nose',
36 35
     'pep8',
37 36
     'mypy',
38 37
 ]

+ 6 - 1
tracim/tests/__init__.py View File

@@ -4,7 +4,7 @@ import transaction
4 4
 from depot.manager import DepotManager
5 5
 from pyramid import testing
6 6
 
7
-from nose.tools import eq_
7
+
8 8
 from tracim.lib.core.content import ContentApi
9 9
 from tracim.lib.core.workspace import WorkspaceApi
10 10
 from tracim.models.data import Workspace, ContentType
@@ -15,6 +15,11 @@ from tracim.fixtures.users_and_groups import Base as BaseFixture
15 15
 from tracim.config import CFG
16 16
 
17 17
 
18
+def eq_(a, b, msg=None):
19
+    # TODO - G.M - 05-04-2018 - Remove this when all old nose code is removed
20
+    assert a == b, msg or "%r != %r" % (a, b)
21
+
22
+
18 23
 class BaseTest(unittest.TestCase):
19 24
     """
20 25
     Pyramid default test.

+ 27 - 24
tracim/tests/library/test_content_api.py View File

@@ -1,9 +1,7 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3
-from nose.tools import eq_, ok_
4
-from nose.tools import raises
5
-
6 3
 import transaction
4
+import pytest
7 5
 
8 6
 from tracim.config import CFG
9 7
 from tracim.lib.core.content import compare_content_for_sorting_by_type_and_name
@@ -28,6 +26,7 @@ from tracim.models.data import ContentType
28 26
 from tracim.models.data import UserRoleInWorkspace
29 27
 from tracim.fixtures.users_and_groups import Test as FixtureTest
30 28
 from tracim.tests import DefaultTest
29
+from tracim.tests import eq_
31 30
 
32 31
 
33 32
 class TestContentApi(DefaultTest):
@@ -387,7 +386,6 @@ class TestContentApi(DefaultTest):
387 386
         eq_(1, len(items2))
388 387
         eq_(child_id, items2[0].content_id)
389 388
 
390
-    @raises(ValueError)
391 389
     def test_set_status_unknown_status(self):
392 390
         uapi = UserApi(
393 391
             session=self.session,
@@ -423,7 +421,8 @@ class TestContentApi(DefaultTest):
423 421
             tm=transaction.manager,
424 422
             content=c,
425 423
         ):
426
-            api.set_status(c, 'unknown-status')
424
+            with pytest.raises(ValueError):
425
+                api.set_status(c, 'unknown-status')
427 426
 
428 427
     def test_set_status_ok(self):
429 428
         uapi = UserApi(
@@ -1210,7 +1209,6 @@ class TestContentApi(DefaultTest):
1210 1209
         eq_('new content', updated.description)
1211 1210
         eq_(ActionDescription.EDITION, updated.revision_type)
1212 1211
 
1213
-    @raises(SameValueError)
1214 1212
     def test_update_no_change(self):
1215 1213
         uapi = UserApi(
1216 1214
             session=self.session,
@@ -1280,11 +1278,12 @@ class TestContentApi(DefaultTest):
1280 1278
            tm=transaction.manager,
1281 1279
            content=content2,
1282 1280
         ):
1283
-            api2.update_content(
1284
-                item=content2,
1285
-                new_label='same_content',
1286
-                new_content='Same_content_here'
1287
-            )
1281
+            with pytest.raises(SameValueError):
1282
+                api2.update_content(
1283
+                    item=content2,
1284
+                    new_label='same_content',
1285
+                    new_content='Same_content_here'
1286
+                )
1288 1287
         api2.save(content2)
1289 1288
         transaction.commit()
1290 1289
 
@@ -1377,8 +1376,12 @@ class TestContentApi(DefaultTest):
1377 1376
             tm=transaction.manager,
1378 1377
             content=content2,
1379 1378
         ):
1380
-            api2.update_file_data(content2, 'index.html', 'text/html',
1381
-                                  b'<html>hello world</html>')
1379
+            api2.update_file_data(
1380
+                content2,
1381
+                'index.html',
1382
+                'text/html',
1383
+                b'<html>hello world</html>'
1384
+            )
1382 1385
         api2.save(content2)
1383 1386
         transaction.commit()
1384 1387
 
@@ -1398,7 +1401,6 @@ class TestContentApi(DefaultTest):
1398 1401
         eq_(b'<html>hello world</html>', updated.depot_file.file.read())
1399 1402
         eq_(ActionDescription.REVISION, updated.revision_type)
1400 1403
 
1401
-    @raises(SameValueError)
1402 1404
     def test_update_no_change(self):
1403 1405
         uapi = UserApi(
1404 1406
             session=self.session,
@@ -1471,12 +1473,13 @@ class TestContentApi(DefaultTest):
1471 1473
             tm=transaction.manager,
1472 1474
             content=content2,
1473 1475
         ):
1474
-            api2.update_file_data(
1475
-                page,
1476
-                'index.html',
1477
-                'text/html',
1478
-                b'<html>Same Content Here</html>'
1479
-            )
1476
+            with pytest.raises(SameValueError):
1477
+                api2.update_file_data(
1478
+                    page,
1479
+                    'index.html',
1480
+                    'text/html',
1481
+                    b'<html>Same Content Here</html>'
1482
+                )
1480 1483
         api2.save(content2)
1481 1484
         transaction.commit()
1482 1485
 
@@ -1985,11 +1988,11 @@ class TestContentApi(DefaultTest):
1985 1988
 
1986 1989
         foo_result = api.search(['foo']).all()
1987 1990
         eq_(1, len(foo_result))
1988
-        ok_(page_1 in foo_result)
1991
+        assert page_1 in foo_result
1989 1992
 
1990 1993
         bar_result = api.search(['bar']).all()
1991 1994
         eq_(1, len(bar_result))
1992
-        ok_(page_2 in bar_result)
1995
+        assert page_2 in bar_result
1993 1996
 
1994 1997
         with new_revision(
1995 1998
             session=self.session,
@@ -2007,11 +2010,11 @@ class TestContentApi(DefaultTest):
2007 2010
         # Actually ContentApi.search don't filter it
2008 2011
         foo_result = api.search(['foo']).all()
2009 2012
         eq_(1, len(foo_result))
2010
-        ok_(page_1 in foo_result)
2013
+        assert page_1 in foo_result
2011 2014
 
2012 2015
         bar_result = api.search(['bar']).all()
2013 2016
         eq_(1, len(bar_result))
2014
-        ok_(page_2 in bar_result)
2017
+        assert page_2 in bar_result
2015 2018
 
2016 2019
         # ContentApi offer exclude_unavailable method to do it
2017 2020
         foo_result = api.search(['foo']).all()

+ 1 - 3
tracim/tests/library/test_notification.py View File

@@ -2,8 +2,6 @@
2 2
 import os
3 3
 import re
4 4
 
5
-from nose.tools import eq_
6
-from nose.tools import ok_
7 5
 
8 6
 from tracim.lib.core.notifications import DummyNotifier
9 7
 from tracim.lib.core.notifications import EmailNotifier
@@ -11,7 +9,7 @@ from tracim.lib.core.notifications import NotifierFactory
11 9
 from tracim.models.auth import User
12 10
 from tracim.models.data import Content
13 11
 from tracim.tests import DefaultTest
14
-
12
+from tracim.tests import eq_
15 13
 
16 14
 class TestDummyNotifier(DefaultTest):
17 15
 

+ 5 - 8
tracim/tests/library/test_user_api.py View File

@@ -1,15 +1,12 @@
1 1
 # -*- coding: utf-8 -*-
2
-
3
-from nose.tools import eq_
4
-from nose.tools import ok_
5
-from nose.tools import raises
6
-
2
+import pytest
7 3
 from sqlalchemy.orm.exc import NoResultFound
8 4
 
9 5
 import transaction
10 6
 
11 7
 from tracim.lib.core.user import UserApi
12 8
 from tracim.tests import DefaultTest
9
+from tracim.tests import eq_
13 10
 
14 11
 
15 12
 class TestUserApi(DefaultTest):
@@ -24,7 +21,7 @@ class TestUserApi(DefaultTest):
24 21
         api.update(u, 'bob', 'bob@bob', True)
25 22
 
26 23
         nu = api.get_one_by_email('bob@bob')
27
-        ok_(nu != None)
24
+        assert nu != None
28 25
         eq_('bob@bob', nu.email)
29 26
         eq_('bob', nu.display_name)
30 27
 
@@ -54,14 +51,14 @@ class TestUserApi(DefaultTest):
54 51
 
55 52
         eq_(uid, api.get_one_by_email('bibi@bibi').user_id)
56 53
 
57
-    @raises(NoResultFound)
58 54
     def test_get_one_by_email_exception(self):
59 55
         api = UserApi(
60 56
             current_user=None,
61 57
             session=self.session,
62 58
             config=self.config,
63 59
         )
64
-        api.get_one_by_email('unknown')
60
+        with pytest.raises(NoResultFound):
61
+            api.get_one_by_email('unknown')
65 62
 
66 63
     def test_get_all(self):
67 64
         # TODO - G.M - 29-03-2018 Check why this method is not enabled

+ 1 - 2
tracim/tests/library/test_workspace.py View File

@@ -1,5 +1,4 @@
1 1
 # -*- coding: utf-8 -*-
2
-from nose.tools import eq_
3 2
 
4 3
 from tracim.lib.core.content import ContentApi
5 4
 from tracim.lib.core.group import GroupApi
@@ -13,7 +12,7 @@ from tracim.models.data import UserRoleInWorkspace
13 12
 from tracim.models.data import Workspace
14 13
 #from tracim.tests import BaseTestThread
15 14
 from tracim.tests import DefaultTest
16
-
15
+from tracim.tests import eq_
17 16
 
18 17
 class TestThread(DefaultTest):
19 18
 

+ 6 - 7
tracim/tests/models/test_content.py View File

@@ -2,11 +2,10 @@
2 2
 import time
3 3
 
4 4
 from depot.fields.upload import UploadedFile
5
-from nose.tools import ok_
6
-from nose.tools import raises
7 5
 from sqlalchemy.sql.elements import and_
8 6
 from sqlalchemy.testing import eq_
9 7
 import transaction
8
+import pytest
10 9
 
11 10
 # from tracim.lib.content import ContentApi
12 11
 from tracim.exceptions import ContentRevisionUpdateError
@@ -23,10 +22,10 @@ from tracim.tests import StandardTest
23 22
 
24 23
 class TestContent(StandardTest):
25 24
 
26
-    @raises(ContentRevisionUpdateError)
27 25
     def test_update_without_prepare(self):
28 26
         content1 = self.test_create()
29
-        content1.description = 'FOO'
27
+        with pytest.raises(ContentRevisionUpdateError):
28
+            content1.description = 'FOO'
30 29
         # Raise ContentRevisionUpdateError because revision can't be updated
31 30
 
32 31
     def test_query(self):
@@ -163,9 +162,9 @@ class TestContent(StandardTest):
163 162
         ).one()
164 163
 
165 164
         # Updated dates must be different
166
-        ok_(revision_1.updated < revision_2.updated < revision_3.updated)
165
+        assert revision_1.updated < revision_2.updated < revision_3.updated
167 166
         # Created dates must be equal
168
-        ok_(revision_1.created == revision_2.created == revision_3.created)
167
+        assert revision_1.created == revision_2.created == revision_3.created
169 168
 
170 169
     def test_creates(self):
171 170
         eq_(
@@ -325,7 +324,7 @@ class TestContent(StandardTest):
325 324
         # which is able to behave like a python file object
326 325
         content.depot_file = b'test'
327 326
         # tests initialized depot file
328
-        ok_(content.depot_file)
327
+        assert content.depot_file
329 328
         # tests type of initialized depot file
330 329
         eq_(type(content.depot_file), UploadedFile)
331 330
         # tests content of initialized depot file

+ 1 - 2
tracim/tests/models/test_content_revision.py View File

@@ -2,13 +2,12 @@
2 2
 from collections import OrderedDict
3 3
 
4 4
 from sqlalchemy import inspect
5
-from nose.tools import eq_
6 5
 
7 6
 from tracim.models import ContentRevisionRO
8 7
 from tracim.models import User
9 8
 from tracim.models.data import ContentType
10 9
 from tracim.tests import DefaultTest
11
-
10
+from tracim.tests import eq_
12 11
 
13 12
 class TestContentRevision(DefaultTest):
14 13
 

+ 1 - 3
tracim/tests/models/test_user.py View File

@@ -1,9 +1,7 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 import transaction
3 3
 
4
-from nose.tools import eq_
5
-from nose.tools import ok_
6
-
4
+from tracim.tests import eq_
7 5
 from tracim.tests import BaseTest
8 6
 
9 7
 from tracim.models.auth import User