| Conditions | 1 |
| Total Lines | 73 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import base64 |
||
| 12 | @classmethod |
||
| 13 | def setUpClass(cls): |
||
| 14 | prefix = "__TestEvaluationPlainHandlerWithAuth_" |
||
| 15 | # create password file |
||
| 16 | cls.pwd_file = tempfile.NamedTemporaryFile( |
||
| 17 | mode="w+t", prefix=prefix, suffix=".txt", delete=False |
||
| 18 | ) |
||
| 19 | username = "username" |
||
| 20 | password = "password" |
||
| 21 | cls.pwd_file.write(f"{username} {hash_password(username, password)}\n")
|
||
| 22 | cls.pwd_file.close() |
||
| 23 | |||
| 24 | # create state.ini dir and file |
||
| 25 | cls.state_dir = tempfile.mkdtemp(prefix=prefix) |
||
| 26 | cls.state_file = open(os.path.join(cls.state_dir, "state.ini"), "w+") |
||
| 27 | cls.state_file.write( |
||
| 28 | "[Service Info]\n" |
||
| 29 | "Name = TabPy Serve\n" |
||
| 30 | "Description = \n" |
||
| 31 | "Creation Time = 0\n" |
||
| 32 | "Access-Control-Allow-Origin = \n" |
||
| 33 | "Access-Control-Allow-Headers = \n" |
||
| 34 | "Access-Control-Allow-Methods = \n" |
||
| 35 | "\n" |
||
| 36 | "[Query Objects Service Versions]\n" |
||
| 37 | "\n" |
||
| 38 | "[Query Objects Docstrings]\n" |
||
| 39 | "\n" |
||
| 40 | "[Meta]\n" |
||
| 41 | "Revision Number = 1\n" |
||
| 42 | ) |
||
| 43 | cls.state_file.close() |
||
| 44 | |||
| 45 | # create config file |
||
| 46 | cls.config_file = tempfile.NamedTemporaryFile( |
||
| 47 | mode="w+t", prefix=prefix, suffix=".conf", delete=False |
||
| 48 | ) |
||
| 49 | cls.config_file.write( |
||
| 50 | "[TabPy]\n" |
||
| 51 | f"TABPY_PWD_FILE = {cls.pwd_file.name}\n"
|
||
| 52 | f"TABPY_STATE_PATH = {cls.state_dir}"
|
||
| 53 | ) |
||
| 54 | cls.config_file.close() |
||
| 55 | |||
| 56 | cls.script = ( |
||
| 57 | '{"data":{"_arg1":[2,3],"_arg2":[3,-1]},'
|
||
| 58 | '"script":"res=[]\\nfor i in range(len(_arg1)):\\n ' |
||
| 59 | 'res.append(_arg1[i] * _arg2[i])\\nreturn res"}' |
||
| 60 | ) |
||
| 61 | |||
| 62 | cls.script_not_present = ( |
||
| 63 | '{"data":{"_arg1":[2,3],"_arg2":[3,-1]},'
|
||
| 64 | '"":"res=[]\\nfor i in range(len(_arg1)):\\n ' |
||
| 65 | 'res.append(_arg1[i] * _arg2[i])\\nreturn res"}' |
||
| 66 | ) |
||
| 67 | |||
| 68 | cls.args_not_present = ( |
||
| 69 | '{"script":"res=[]\\nfor i in range(len(_arg1)):\\n '
|
||
| 70 | 'res.append(_arg1[i] * _arg2[i])\\nreturn res"}' |
||
| 71 | ) |
||
| 72 | |||
| 73 | cls.args_not_sequential = ( |
||
| 74 | '{"data":{"_arg1":[2,3],"_arg3":[3,-1]},'
|
||
| 75 | '"script":"res=[]\\nfor i in range(len(_arg1)):\\n ' |
||
| 76 | 'res.append(_arg1[i] * _arg3[i])\\nreturn res"}' |
||
| 77 | ) |
||
| 78 | |||
| 79 | cls.nan_coverts_to_null =\ |
||
| 80 | '{"data":{"_arg1":[2,3],"_arg2":[3,-1]},'\
|
||
| 81 | '"script":"return [float(1), float(\\"NaN\\"), float(2)]"}' |
||
| 82 | |||
| 83 | cls.script_returns_none = ( |
||
| 84 | '{"data":{"_arg1":[2,3],"_arg2":[3,-1]},'
|
||
| 85 | '"script":"return None"}' |
||
| 206 |