| | | |
Offset 3349, 15 lines modified | Offset 3349, 15 lines modified |
3349 | Any·Pecan·application·can·be·controlled·and·inspected·from·the·command | 3349 | Any·Pecan·application·can·be·controlled·and·inspected·from·the·command |
3350 | line·using·the·built\-in·\fBpecan\fP·command.··The·usage·examples | 3350 | line·using·the·built\-in·\fBpecan\fP·command.··The·usage·examples |
3351 | of·\fBpecan\fP·in·this·document·are·intended·to·be·invoked·from | 3351 | of·\fBpecan\fP·in·this·document·are·intended·to·be·invoked·from |
3352 | your·project\(aqs·root·directory. | 3352 | your·project\(aqs·root·directory. |
3353 | .SS·Serving·a·Pecan·App·For·Development | 3353 | .SS·Serving·a·Pecan·App·For·Development |
3354 | .sp | 3354 | .sp |
3355 | Pecan·comes·bundled·with·a·lightweight·WSGI·development·server·based·on | 3355 | Pecan·comes·bundled·with·a·lightweight·WSGI·development·server·based·on |
3356 | Python\(aqs·\fI\%wsgiref.simple_server\fP·module. | 3356 | Python\(aqs·\fBwsgiref.simple_server\fP·module. |
3357 | .sp | 3357 | .sp |
3358 | Serving·your·Pecan·app·is·as·simple·as·invoking·the·\fBpecan·serve\fP·command: | 3358 | Serving·your·Pecan·app·is·as·simple·as·invoking·the·\fBpecan·serve\fP·command: |
3359 | .INDENT·0.0 | 3359 | .INDENT·0.0 |
3360 | .INDENT·3.5 | 3360 | .INDENT·3.5 |
3361 | .sp | 3361 | .sp |
3362 | .nf | 3362 | .nf |
3363 | .ft·C | 3363 | .ft·C |
Offset 3564, 30 lines modified | Offset 3564, 30 lines modified |
3564 | .sp | 3564 | .sp |
3565 | First,·we\(aqre·subclassing·\fI\%BaseCommand\fP·and·extending | 3565 | First,·we\(aqre·subclassing·\fI\%BaseCommand\fP·and·extending |
3566 | the·\fI\%run()\fP·method·to: | 3566 | the·\fI\%run()\fP·method·to: |
3567 | .INDENT·0.0 | 3567 | .INDENT·0.0 |
3568 | .IP·\(bu·2 | 3568 | .IP·\(bu·2 |
3569 | Load·a·Pecan·application·\-·\fI\%load_app()\fP | 3569 | Load·a·Pecan·application·\-·\fI\%load_app()\fP |
3570 | .IP·\(bu·2 | 3570 | .IP·\(bu·2 |
3571 | Wrap·it·in·a·fake·WGSI·environment·\-·\fI\%TestApp\fP | 3571 | Wrap·it·in·a·fake·WGSI·environment·\-·\fBTestApp\fP |
3572 | .IP·\(bu·2 | 3572 | .IP·\(bu·2 |
3573 | Issue·an·HTTP·GET·request·against·it·\-·\fI\%get()\fP | 3573 | Issue·an·HTTP·GET·request·against·it·\-·\fBget()\fP |
3574 | .UNINDENT | 3574 | .UNINDENT |
3575 | .SS·Defining·Custom·Arguments | 3575 | .SS·Defining·Custom·Arguments |
3576 | .sp | 3576 | .sp |
3577 | The·\fBarguments\fP·class·attribute·is·used·to·define·command·line·arguments | 3577 | The·\fBarguments\fP·class·attribute·is·used·to·define·command·line·arguments |
3578 | specific·to·your·custom·command.··You\(aqll·notice·in·this·example·that·we\(aqre | 3578 | specific·to·your·custom·command.··You\(aqll·notice·in·this·example·that·we\(aqre |
3579 | \fIadding\fP·to·the·arguments·list·provided·by·\fI\%BaseCommand\fP | 3579 | \fIadding\fP·to·the·arguments·list·provided·by·\fI\%BaseCommand\fP |
3580 | (which·already·provides·an·argument·for·the·\fBconfig_file\fP),·rather | 3580 | (which·already·provides·an·argument·for·the·\fBconfig_file\fP),·rather |
3581 | than·overriding·it·entirely. | 3581 | than·overriding·it·entirely. |
3582 | .sp | 3582 | .sp |
3583 | The·format·of·the·\fBarguments\fP·class·attribute·is·a·\fI\%tuple\fP·of | 3583 | The·format·of·the·\fBarguments\fP·class·attribute·is·a·\fBtuple\fP·of |
3584 | dictionaries,·with·each·dictionary·representing·an·argument·definition·in·the | 3584 | dictionaries,·with·each·dictionary·representing·an·argument·definition·in·the |
3585 | same·format·accepted·by·Python\(aqs·\fI\%argparse\fP·module·(more·specifically, | 3585 | same·format·accepted·by·Python\(aqs·\fBargparse\fP·module·(more·specifically, |
3586 | \fI\%add_argument()\fP).··By·providing·a·list·of | 3586 | \fBadd_argument()\fP).··By·providing·a·list·of |
3587 | arguments·in·this·format,·the·\fBpecan\fP·command·can·include·your·custom | 3587 | arguments·in·this·format,·the·\fBpecan\fP·command·can·include·your·custom |
3588 | commands·in·the·help·and·usage·output·it·provides. | 3588 | commands·in·the·help·and·usage·output·it·provides. |
3589 | .INDENT·0.0 | 3589 | .INDENT·0.0 |
3590 | .INDENT·3.5 | 3590 | .INDENT·3.5 |
3591 | .sp | 3591 | .sp |
3592 | .nf | 3592 | .nf |
3593 | .ft·C | 3593 | .ft·C |
Offset 4139, 15 lines modified | Offset 4139, 15 lines modified |
4139 | $·python·run.py | 4139 | $·python·run.py |
4140 | .ft·P | 4140 | .ft·P |
4141 | .fi | 4141 | .fi |
4142 | .UNINDENT | 4142 | .UNINDENT |
4143 | .UNINDENT | 4143 | .UNINDENT |
4144 | .SH·LOGGING | 4144 | .SH·LOGGING |
4145 | .sp | 4145 | .sp |
4146 | Pecan·uses·the·Python·standard·library\(aqs·\fI\%logging\fP·module·by·passing | 4146 | Pecan·uses·the·Python·standard·library\(aqs·\fBlogging\fP·module·by·passing |
4147 | logging·configuration·options·into·the·\fI\%logging.config.dictConfig\fP | 4147 | logging·configuration·options·into·the·\fI\%logging.config.dictConfig\fP |
4148 | function.··The·full·documentation·for·the·\fBdictConfig()\fP·format·is | 4148 | function.··The·full·documentation·for·the·\fBdictConfig()\fP·format·is |
4149 | the·best·source·of·information·for·logging·configuration,·but·to·get | 4149 | the·best·source·of·information·for·logging·configuration,·but·to·get |
4150 | you·started,·this·chapter·will·provide·you·with·a·few·simple·examples. | 4150 | you·started,·this·chapter·will·provide·you·with·a·few·simple·examples. |
4151 | .SS·Configuring·Logging | 4151 | .SS·Configuring·Logging |
4152 | .sp | 4152 | .sp |
4153 | Sample·logging·configuration·is·provided·with·the·quickstart·project | 4153 | Sample·logging·configuration·is·provided·with·the·quickstart·project |
Offset 4234, 27 lines modified | Offset 4234, 27 lines modified |
4234 | ········return·dict() | 4234 | ········return·dict() |
4235 | .ft·P | 4235 | .ft·P |
4236 | .fi | 4236 | .fi |
4237 | .UNINDENT | 4237 | .UNINDENT |
4238 | .UNINDENT | 4238 | .UNINDENT |
4239 | .SS·Logging·to·Files·and·Other·Locations | 4239 | .SS·Logging·to·Files·and·Other·Locations |
4240 | .sp | 4240 | .sp |
4241 | Python\(aqs·\fI\%logging\fP·library·defines·a·variety·of·handlers·that·assist·in | 4241 | Python\(aqs·\fBlogging\fP·library·defines·a·variety·of·handlers·that·assist·in |
4242 | writing·logs·to·file.··A·few·interesting·ones·are: | 4242 | writing·logs·to·file.··A·few·interesting·ones·are: |
4243 | .INDENT·0.0 | 4243 | .INDENT·0.0 |
4244 | .IP·\(bu·2 | 4244 | .IP·\(bu·2 |
4245 | \fI\%FileHandler\fP·\-·used·to·log·messages·to·a·file·on·the·filesystem | 4245 | \fBFileHandler\fP·\-·used·to·log·messages·to·a·file·on·the·filesystem |
4246 | .IP·\(bu·2 | 4246 | .IP·\(bu·2 |
4247 | \fI\%RotatingFileHandler\fP·\-·similar·to | 4247 | \fBRotatingFileHandler\fP·\-·similar·to |
4248 | \fI\%FileHandler\fP,·but·also·rotates·logs | 4248 | \fBFileHandler\fP,·but·also·rotates·logs |
4249 | periodically | 4249 | periodically |
4250 | .IP·\(bu·2 | 4250 | .IP·\(bu·2 |
4251 | \fI\%SysLogHandler\fP·\-·used·to·log·messages·to·a·UNIX·syslog | 4251 | \fBSysLogHandler\fP·\-·used·to·log·messages·to·a·UNIX·syslog |
4252 | .IP·\(bu·2 | 4252 | .IP·\(bu·2 |
4253 | \fI\%SMTPHandler\fP·\-·used·to·log·messages·to·an·email | 4253 | \fBSMTPHandler\fP·\-·used·to·log·messages·to·an·email |
4254 | address·via·SMTP | 4254 | address·via·SMTP |
4255 | .UNINDENT | 4255 | .UNINDENT |
4256 | .sp | 4256 | .sp |
4257 | Using·any·of·them·is·as·simple·as·defining·a·new·handler·in·your | 4257 | Using·any·of·them·is·as·simple·as·defining·a·new·handler·in·your |
4258 | application\(aqs·\fBlogging\fP·block·and·assigning·it·to·one·of·more·loggers. | 4258 | application\(aqs·\fBlogging\fP·block·and·assigning·it·to·one·of·more·loggers. |
4259 | .SS·Logging·Requests·with·Paste·Translogger | 4259 | .SS·Logging·Requests·with·Paste·Translogger |
4260 | .sp | 4260 | .sp |
Offset 4326, 15 lines modified | Offset 4326, 15 lines modified |
4326 | .UNINDENT | 4326 | .UNINDENT |
4327 | .SH·TESTING·PECAN·APPLICATIONS | 4327 | .SH·TESTING·PECAN·APPLICATIONS |
4328 | .sp | 4328 | .sp |
4329 | Tests·can·live·anywhere·in·your·Pecan·project·as·long·as·the·test·runner·can | 4329 | Tests·can·live·anywhere·in·your·Pecan·project·as·long·as·the·test·runner·can |
4330 | discover·them.·Traditionally,·they·exist·in·a·package·named·\fBmyapp.tests\fP\&. | 4330 | discover·them.·Traditionally,·they·exist·in·a·package·named·\fBmyapp.tests\fP\&. |
4331 | .sp | 4331 | .sp |
4332 | The·suggested·mechanism·for·unit·and·integration·testing·of·a·Pecan·application | 4332 | The·suggested·mechanism·for·unit·and·integration·testing·of·a·Pecan·application |
4333 | is·the·\fI\%unittest\fP·module. | 4333 | is·the·\fBunittest\fP·module. |
4334 | .SS·Test·Discovery·and·Other·Tools | 4334 | .SS·Test·Discovery·and·Other·Tools |
4335 | .sp | 4335 | .sp |
4336 | Tests·for·a·Pecan·project·can·be·invoked·as·simply·as·\fBpython·setup.py·test\fP, | 4336 | Tests·for·a·Pecan·project·can·be·invoked·as·simply·as·\fBpython·setup.py·test\fP, |
4337 | though·it\(aqs·possible·to·run·your·tests·with·different·discovery·and·automation | 4337 | though·it\(aqs·possible·to·run·your·tests·with·different·discovery·and·automation |
4338 | tools.··In·particular,·Pecan·projects·are·known·to·work·well·with | 4338 | tools.··In·particular,·Pecan·projects·are·known·to·work·well·with |
4339 | \fI\%nose\fP,·\fI\%pytest\fP, | 4339 | \fI\%nose\fP,·\fI\%pytest\fP, |
4340 | and·\fI\%tox\fP\&. | 4340 | and·\fI\%tox\fP\&. |
Offset 4342, 15 lines modified | Offset 4342, 15 lines modified |
4342 | .sp | 4342 | .sp |
4343 | A·\fBunit·test\fP·typically·relies·on·\(dqmock\(dq·or·\(dqfake\(dq·objects·to·give·the·code | 4343 | A·\fBunit·test\fP·typically·relies·on·\(dqmock\(dq·or·\(dqfake\(dq·objects·to·give·the·code |
4344 | under·test·enough·context·to·run.··In·this·way,·only·an·individual·unit·of | 4344 | under·test·enough·context·to·run.··In·this·way,·only·an·individual·unit·of |
4345 | source·code·is·tested. | 4345 | source·code·is·tested. |
4346 | .sp | 4346 | .sp |
4347 | A·healthy·suite·of·tests·combines·\fBunit·tests\fP·with·\fBfunctional·tests\fP\&.··In | 4347 | A·healthy·suite·of·tests·combines·\fBunit·tests\fP·with·\fBfunctional·tests\fP\&.··In |
4348 | the·context·of·a·Pecan·application,·functional·tests·can·be·written·with·the | 4348 | the·context·of·a·Pecan·application,·functional·tests·can·be·written·with·the |
4349 | help·of·the·\fI\%webtest\fP·library.··In·this·way,·it·is·possible·to·write·tests | 4349 | help·of·the·\fBwebtest\fP·library.··In·this·way,·it·is·possible·to·write·tests |
4350 | that·verify·the·behavior·of·an·HTTP·request·life·cycle·from·the·controller | 4350 | that·verify·the·behavior·of·an·HTTP·request·life·cycle·from·the·controller |
4351 | routing·down·to·the·HTTP·response.··The·following·is·an·example·that·is | 4351 | routing·down·to·the·HTTP·response.··The·following·is·an·example·that·is |
4352 | similar·to·the·one·included·with·Pecan\(aqs·quickstart·project. | 4352 | similar·to·the·one·included·with·Pecan\(aqs·quickstart·project. |
4353 | .INDENT·0.0 | 4353 | .INDENT·0.0 |
4354 | .INDENT·3.5 | 4354 | .INDENT·3.5 |
4355 | .sp | 4355 | .sp |
4356 | .nf | 4356 | .nf |
Offset 4379, 15 lines modified | Offset 4379, 15 lines modified |
4379 | .ft·P | 4379 | .ft·P |
4380 | .fi | 4380 | .fi |
4381 | .UNINDENT | 4381 | .UNINDENT |
4382 | .UNINDENT | 4382 | .UNINDENT |
Max diff block lines reached; 9425/14912 bytes (63.20%) of diff not shown.
|