Browse Source

remove nose

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

+ 0 - 1
setup.py View File

32
     'WebTest >= 1.3.1',  # py3 compat
32
     'WebTest >= 1.3.1',  # py3 compat
33
     'pytest',
33
     'pytest',
34
     'pytest-cov',
34
     'pytest-cov',
35
-    'nose',
36
     'pep8',
35
     'pep8',
37
     'mypy',
36
     'mypy',
38
 ]
37
 ]

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

4
 from depot.manager import DepotManager
4
 from depot.manager import DepotManager
5
 from pyramid import testing
5
 from pyramid import testing
6
 
6
 
7
-from nose.tools import eq_
7
+
8
 from tracim.lib.core.content import ContentApi
8
 from tracim.lib.core.content import ContentApi
9
 from tracim.lib.core.workspace import WorkspaceApi
9
 from tracim.lib.core.workspace import WorkspaceApi
10
 from tracim.models.data import Workspace, ContentType
10
 from tracim.models.data import Workspace, ContentType
15
 from tracim.config import CFG
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
 class BaseTest(unittest.TestCase):
23
 class BaseTest(unittest.TestCase):
19
     """
24
     """
20
     Pyramid default test.
25
     Pyramid default test.

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

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

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

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

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

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

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

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

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

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

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

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
 import transaction
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
 from tracim.tests import BaseTest
5
 from tracim.tests import BaseTest
8
 
6
 
9
 from tracim.models.auth import User
7
 from tracim.models.auth import User