Mercurial > silorider
comparison tests/conftest.py @ 19:d3c4c5082bbc
Add Webmention silo.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 02 Oct 2018 22:22:31 -0700 |
parents | a921cc2306bc |
children | b404445082f8 |
comparison
equal
deleted
inserted
replaced
18:a921cc2306bc | 19:d3c4c5082bbc |
---|---|
4 import re | 4 import re |
5 import logging | 5 import logging |
6 import tempfile | 6 import tempfile |
7 import pytest | 7 import pytest |
8 import silorider.main | 8 import silorider.main |
9 | |
10 | |
11 logger = logging.getLogger(__name__) | |
9 | 12 |
10 | 13 |
11 # def pytest_collect_file(parent, path): | 14 # def pytest_collect_file(parent, path): |
12 # if path.ext == ".html" and path.basename.startswith("feeds"): | 15 # if path.ext == ".html" and path.basename.startswith("feeds"): |
13 # return FeedFile(path, parent) | 16 # return FeedFile(path, parent) |
89 | 92 |
90 def preExecHook(self, hook): | 93 def preExecHook(self, hook): |
91 self._pre_hooks.append(hook) | 94 self._pre_hooks.append(hook) |
92 | 95 |
93 def run(self, *args): | 96 def run(self, *args): |
94 pre_args = [] | 97 pre_args = ['-v'] |
95 if self._cfgtxt or self._feedcfg: | 98 if self._cfgtxt or self._feedcfg: |
96 cfgtxt = self._cfgtxt | 99 cfgtxt = self._cfgtxt |
97 cfgtxt += '\n\n[urls]\n' | 100 cfgtxt += '\n\n[urls]\n' |
98 for n, u in self._feedcfg: | 101 for n, u in self._feedcfg: |
99 cfgtxt += '%s=%s\n' % (n, u) | 102 cfgtxt += '%s=%s\n' % (n, u) |
100 | 103 |
101 tmpfd, tmpcfg = tempfile.mkstemp() | 104 tmpfd, tmpcfg = tempfile.mkstemp() |
102 print("Creating temporary configuration file: %s" % tmpcfg) | 105 logger.info("Creating temporary configuration file: %s" % tmpcfg) |
103 with os.fdopen(tmpfd, 'w') as tmpfp: | 106 with os.fdopen(tmpfd, 'w') as tmpfp: |
104 tmpfp.write(cfgtxt) | 107 tmpfp.write(cfgtxt) |
105 self._cleanup.append(tmpcfg) | 108 self._cleanup.append(tmpcfg) |
106 pre_args = ['-c', tmpcfg] | 109 pre_args += ['-c', tmpcfg] |
107 | 110 |
108 captured = io.StringIO() | 111 captured = io.StringIO() |
109 handler = logging.StreamHandler(captured) | 112 handler = logging.StreamHandler(captured) |
110 handler.setLevel(logging.INFO) | 113 handler.setLevel(logging.INFO) |
111 silorider_logger = logging.getLogger('silorider') | 114 silorider_logger = logging.getLogger('silorider') |
125 | 128 |
126 silorider.main.pre_exec_hook = pre_exec_hook | 129 silorider.main.pre_exec_hook = pre_exec_hook |
127 silorider.main.post_exec_hook = post_exec_hook | 130 silorider.main.post_exec_hook = post_exec_hook |
128 | 131 |
129 args = pre_args + list(args) | 132 args = pre_args + list(args) |
130 print("Running command: %s" % list(args)) | 133 logger.info("Running command: %s" % list(args)) |
131 try: | 134 try: |
132 silorider.main._unsafe_main(args) | 135 silorider.main._unsafe_main(args) |
133 finally: | 136 finally: |
134 silorider.main.pre_exec_hook = None | 137 silorider.main.pre_exec_hook = None |
135 silorider.main.post_exec_hook = None | 138 silorider.main.post_exec_hook = None |
136 | 139 |
137 silorider_logger.removeHandler(handler) | 140 silorider_logger.removeHandler(handler) |
138 | 141 |
139 print("Cleaning %d temporary files." % len(self._cleanup)) | 142 logger.info("Cleaning %d temporary files." % len(self._cleanup)) |
140 for tmpname in self._cleanup: | 143 for tmpname in self._cleanup: |
141 try: | 144 try: |
142 os.remove(tmpname) | 145 os.remove(tmpname) |
143 except FileNotFoundError: | 146 except FileNotFoundError: |
144 pass | 147 pass |