| 1 | MISSING: tests for nearly everything that has to do with the config file (i.e. |
|---|
| 2 | no permissions, external changes, etc) |
|---|
| 3 | tests for some parts of Configuration's dict interface (iter* etc) |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | Basics: |
|---|
| 7 | |
|---|
| 8 | >>> app.cfg # doctest: +ELLIPSIS |
|---|
| 9 | <Configuration ...> |
|---|
| 10 | >>> app.cfg['blog_title'] |
|---|
| 11 | iu'My Zine Blog' |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | Are those changes written to the config file correctly? |
|---|
| 15 | |
|---|
| 16 | >>> app.cfg.change_single('pings_enabled', False) |
|---|
| 17 | >>> [line for line in open(app.cfg.filename) if 'pings_enabled' in line][0] |
|---|
| 18 | 'pings_enabled = False\n' |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | Basic transaction test. Also tests that default values are not written to the |
|---|
| 22 | config file. |
|---|
| 23 | |
|---|
| 24 | >>> t = app.cfg.edit() |
|---|
| 25 | >>> t['pings_enabled'] = True |
|---|
| 26 | >>> t['blog_title'] |
|---|
| 27 | iu'My Zine Blog' |
|---|
| 28 | >>> t['blog_title'] = 'Another Blog Title' |
|---|
| 29 | >>> t.commit() |
|---|
| 30 | >>> len([line for line in open(app.cfg.filename) if 'pings_enabled' in line]) |
|---|
| 31 | 0 |
|---|
| 32 | >>> app.cfg['blog_title'] |
|---|
| 33 | u'Another Blog Title' |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | Test revert_to_default |
|---|
| 37 | |
|---|
| 38 | >>> t = app.cfg.edit() |
|---|
| 39 | >>> t.revert_to_default('blog_title') |
|---|
| 40 | >>> t['blog_title'] |
|---|
| 41 | iu'My Zine Blog' |
|---|
| 42 | >>> t.commit() |
|---|
| 43 | >>> app.cfg['blog_title'] |
|---|
| 44 | iu'My Zine Blog' |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | Transactions can only be committed once: |
|---|
| 48 | |
|---|
| 49 | >>> t.commit() |
|---|
| 50 | Traceback (most recent call last): |
|---|
| 51 | ... |
|---|
| 52 | ValueError: This transaction was already committed. |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | Somewhat bigger transaction. Tests update(), set_from_string() and if changes |
|---|
| 56 | are really only written to the config when the transaction is committed. |
|---|
| 57 | |
|---|
| 58 | >>> big_t = app.cfg.edit() |
|---|
| 59 | >>> big_t.update({'zine/blog_tagline': '...and the test goes on', |
|---|
| 60 | ... 'language': 'de'}) |
|---|
| 61 | >>> big_t['blog_tagline'] |
|---|
| 62 | u'...and the test goes on' |
|---|
| 63 | >>> app.cfg['blog_tagline'] |
|---|
| 64 | iu'just another Zine blog' |
|---|
| 65 | >>> app.cfg['language'] |
|---|
| 66 | u'en' |
|---|
| 67 | >>> big_t.set_from_string('zine/posts_per_page', '42') |
|---|
| 68 | >>> big_t.commit() |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | Was the transaction commited correctly? |
|---|
| 72 | |
|---|
| 73 | >>> app.cfg['zine/language'] |
|---|
| 74 | u'de' |
|---|
| 75 | >>> app.cfg['blog_tagline'] |
|---|
| 76 | u'...and the test goes on' |
|---|
| 77 | >>> app.cfg['posts_per_page'] |
|---|
| 78 | 42 |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | Handling of inexisting keys |
|---|
| 82 | |
|---|
| 83 | >>> app.cfg.change_single('inexisting_key', 23) |
|---|
| 84 | Traceback (most recent call last): |
|---|
| 85 | ... |
|---|
| 86 | KeyError: 'inexisting_key' |
|---|
| 87 | >>> app.cfg['inexisting_key'] |
|---|
| 88 | Traceback (most recent call last): |
|---|
| 89 | ... |
|---|
| 90 | KeyError: 'inexisting_key' |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | __contains__ |
|---|
| 94 | |
|---|
| 95 | >>> 'zine/blog_title' in app.cfg |
|---|
| 96 | True |
|---|
| 97 | >>> 'foobar' in app.cfg |
|---|
| 98 | False |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | Reset the config so future tests get the same initial values |
|---|
| 102 | |
|---|
| 103 | >>> reset = app.cfg.edit() |
|---|
| 104 | >>> reset.revert_to_default('zine/blog_tagline') |
|---|
| 105 | >>> reset.revert_to_default('posts_per_page') |
|---|
| 106 | >>> reset.revert_to_default('language') |
|---|
| 107 | >>> reset.commit() |
|---|