forked from tortoise/tortoise-orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_run_async.py
More file actions
43 lines (34 loc) · 1.37 KB
/
test_run_async.py
File metadata and controls
43 lines (34 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
from unittest import skipIf
from tortoise import Tortoise, connections, run_async
from tortoise.contrib.test import TestCase
@skipIf(os.name == "nt", "stuck with Windows")
class TestRunAsync(TestCase):
async def asyncSetUp(self) -> None:
pass
async def asyncTearDown(self) -> None:
pass
def setUp(self):
self.somevalue = 1
async def init(self):
await Tortoise.init(db_url="sqlite://:memory:", modules={"models": []})
self.somevalue = 2
self.assertNotEqual(connections._get_storage(), {})
async def init_raise(self):
await Tortoise.init(db_url="sqlite://:memory:", modules={"models": []})
self.somevalue = 3
self.assertNotEqual(connections._get_storage(), {})
raise Exception("Some exception")
def test_run_async(self):
self.assertEqual(connections._get_storage(), {})
self.assertEqual(self.somevalue, 1)
run_async(self.init())
self.assertEqual(connections._get_storage(), {})
self.assertEqual(self.somevalue, 2)
def test_run_async_raised(self):
self.assertEqual(connections._get_storage(), {})
self.assertEqual(self.somevalue, 1)
with self.assertRaises(Exception):
run_async(self.init_raise())
self.assertEqual(connections._get_storage(), {})
self.assertEqual(self.somevalue, 3)