mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
refactor: make loader as submodule
This commit is contained in:
0
tests/test_loader/__init__.py
Normal file
0
tests/test_loader/__init__.py
Normal file
76
tests/test_loader/test_check.py
Normal file
76
tests/test_loader/test_check.py
Normal file
@@ -0,0 +1,76 @@
|
||||
import unittest
|
||||
|
||||
from httprunner.loader import check
|
||||
|
||||
|
||||
class TestLoaderCheck(unittest.TestCase):
|
||||
|
||||
def test_is_function(self):
|
||||
func = lambda x: x + 1
|
||||
self.assertTrue(check.is_function(func))
|
||||
self.assertTrue(check.is_function(check.is_testcase))
|
||||
|
||||
def test_is_testcases(self):
|
||||
data_structure = "path/to/file"
|
||||
self.assertFalse(check.is_testcases(data_structure))
|
||||
data_structure = ["path/to/file1", "path/to/file2"]
|
||||
self.assertFalse(check.is_testcases(data_structure))
|
||||
|
||||
data_structure = {
|
||||
"project_mapping": {
|
||||
"PWD": "XXXXX",
|
||||
"functions": {},
|
||||
"env": {}
|
||||
},
|
||||
"testcases": [
|
||||
{ # testcase data structure
|
||||
"config": {
|
||||
"name": "desc1",
|
||||
"path": "testcase1_path",
|
||||
"variables": [], # optional
|
||||
},
|
||||
"teststeps": [
|
||||
# test data structure
|
||||
{
|
||||
'name': 'test step desc1',
|
||||
'variables': [], # optional
|
||||
'extract': [], # optional
|
||||
'validate': [],
|
||||
'request': {}
|
||||
},
|
||||
# test_dict2 # another test dict
|
||||
]
|
||||
},
|
||||
# testcase_dict_2 # another testcase dict
|
||||
]
|
||||
}
|
||||
self.assertTrue(check.is_testcases(data_structure))
|
||||
data_structure = [
|
||||
{
|
||||
"name": "desc1",
|
||||
"config": {},
|
||||
"api": {},
|
||||
"testcases": ["testcase11", "testcase12"]
|
||||
},
|
||||
{
|
||||
"name": "desc2",
|
||||
"config": {},
|
||||
"api": {},
|
||||
"testcases": ["testcase21", "testcase22"]
|
||||
}
|
||||
]
|
||||
self.assertTrue(data_structure)
|
||||
|
||||
def test_is_variable(self):
|
||||
var1 = 123
|
||||
var2 = "abc"
|
||||
self.assertTrue(check.is_variable(("var1", var1)))
|
||||
self.assertTrue(check.is_variable(("var2", var2)))
|
||||
|
||||
__var = 123
|
||||
self.assertFalse(check.is_variable(("__var", __var)))
|
||||
|
||||
func = lambda x: x + 1
|
||||
self.assertFalse(check.is_variable(("func", func)))
|
||||
|
||||
self.assertFalse(check.is_variable(("unittest", unittest)))
|
||||
@@ -476,73 +476,3 @@ class TestSuiteLoader(unittest.TestCase):
|
||||
api_file_path = os.path.join(os.getcwd(), "tests", "api", "get_token.yml")
|
||||
self.assertIn(api_file_path, self.tests_def_mapping["api"])
|
||||
self.assertEqual(self.project_mapping["env"]["PROJECT_KEY"], "ABCDEFGH")
|
||||
|
||||
def test_is_function(self):
|
||||
func = lambda x: x + 1
|
||||
self.assertTrue(loader.is_function(func))
|
||||
self.assertTrue(loader.is_function(loader.is_testcase))
|
||||
|
||||
def test_is_testcases(self):
|
||||
data_structure = "path/to/file"
|
||||
self.assertFalse(loader.is_testcases(data_structure))
|
||||
data_structure = ["path/to/file1", "path/to/file2"]
|
||||
self.assertFalse(loader.is_testcases(data_structure))
|
||||
|
||||
data_structure = {
|
||||
"project_mapping": {
|
||||
"PWD": "XXXXX",
|
||||
"functions": {},
|
||||
"env": {}
|
||||
},
|
||||
"testcases": [
|
||||
{ # testcase data structure
|
||||
"config": {
|
||||
"name": "desc1",
|
||||
"path": "testcase1_path",
|
||||
"variables": [], # optional
|
||||
},
|
||||
"teststeps": [
|
||||
# test data structure
|
||||
{
|
||||
'name': 'test step desc1',
|
||||
'variables': [], # optional
|
||||
'extract': [], # optional
|
||||
'validate': [],
|
||||
'request': {}
|
||||
},
|
||||
# test_dict2 # another test dict
|
||||
]
|
||||
},
|
||||
# testcase_dict_2 # another testcase dict
|
||||
]
|
||||
}
|
||||
self.assertTrue(loader.is_testcases(data_structure))
|
||||
data_structure = [
|
||||
{
|
||||
"name": "desc1",
|
||||
"config": {},
|
||||
"api": {},
|
||||
"testcases": ["testcase11", "testcase12"]
|
||||
},
|
||||
{
|
||||
"name": "desc2",
|
||||
"config": {},
|
||||
"api": {},
|
||||
"testcases": ["testcase21", "testcase22"]
|
||||
}
|
||||
]
|
||||
self.assertTrue(data_structure)
|
||||
|
||||
def test_is_variable(self):
|
||||
var1 = 123
|
||||
var2 = "abc"
|
||||
self.assertTrue(loader.is_variable(("var1", var1)))
|
||||
self.assertTrue(loader.is_variable(("var2", var2)))
|
||||
|
||||
__var = 123
|
||||
self.assertFalse(loader.is_variable(("__var", __var)))
|
||||
|
||||
func = lambda x: x + 1
|
||||
self.assertFalse(loader.is_variable(("func", func)))
|
||||
|
||||
self.assertFalse(loader.is_variable(("unittest", unittest)))
|
||||
Reference in New Issue
Block a user