Conditions | 1 |
Total Lines | 62 |
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 | from nose.tools import assert_true, assert_equal, assert_raises |
||
78 | def test_str(self): |
||
79 | # Create simple PBS file |
||
80 | expected = """#!/bin/bash |
||
81 | #PBS -q qtest@mp2 |
||
82 | #PBS -V |
||
83 | #PBS -l walltime=01:00:00 |
||
84 | |||
85 | # Modules # |
||
86 | |||
87 | # Prolog # |
||
88 | |||
89 | # Commands # |
||
90 | |||
91 | # Epilog #""" |
||
92 | pbs = PBS(queue_name="qtest@mp2", walltime="01:00:00") |
||
93 | assert_equal(str(pbs), expected) |
||
94 | |||
95 | # Create a more complex PBS file |
||
96 | prolog = ['echo "This is prolog1"', |
||
97 | 'echo "This is prolog2"'] |
||
98 | commands = ["cd $HOME; echo 1 2 3 1>> cmd1.o 2>> cmd1.e", |
||
99 | "cd $HOME; echo 3 2 1 1>> cmd1.o 2>> cmd1.e"] |
||
100 | epilog = ['echo "This is epilog1"', |
||
101 | 'echo "This is epilog2"'] |
||
102 | modules = ["CUDA_Toolkit/6.0", "python2.7"] |
||
103 | |||
104 | expected = """\ |
||
105 | #!/bin/bash |
||
106 | #PBS -q qtest@mp2 |
||
107 | #PBS -V |
||
108 | #PBS -A xyz-123-ab |
||
109 | #PBS -l walltime=01:00:00 |
||
110 | #PBS -l nodes=2:ppn=3:gpus=1 |
||
111 | |||
112 | # Modules # |
||
113 | module load CUDA_Toolkit/6.0 |
||
114 | module load python2.7 |
||
115 | |||
116 | # Prolog # |
||
117 | {prolog1} |
||
118 | {prolog2} |
||
119 | |||
120 | # Commands # |
||
121 | {command1} |
||
122 | {command2} |
||
123 | |||
124 | # Epilog # |
||
125 | {epilog1} |
||
126 | {epilog2}""".format( |
||
127 | prolog1=prolog[0], prolog2=prolog[1], |
||
128 | command1=commands[0], command2=commands[1], |
||
129 | epilog1=epilog[0], epilog2=epilog[1]) |
||
130 | |||
131 | pbs = PBS(queue_name="qtest@mp2", walltime="01:00:00") |
||
132 | pbs.add_resources(nodes="2:ppn=3:gpus=1") |
||
133 | pbs.add_options(A="xyz-123-ab") |
||
134 | pbs.add_modules_to_load(*modules) |
||
135 | pbs.add_to_prolog(*prolog) |
||
136 | pbs.add_commands(*commands) |
||
137 | pbs.add_to_epilog(*epilog) |
||
138 | |||
139 | assert_equal(str(pbs), expected) |
||
140 | |||
145 |