comparison tests/conftest.py @ 18:a921cc2306bc

Do our own HTML parsing/stripping of micropost contents. - This lets us properly handle various forms of linking. - Add tests for processing posts with links. - Fix configuration in tests. - Basic error handling for processing posts.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 16 Sep 2018 21:16:20 -0700
parents a1b7a459326a
children d3c4c5082bbc
comparison
equal deleted inserted replaced
17:678278cb85b1 18:a921cc2306bc
45 def __init__(self): 45 def __init__(self):
46 self._cfgtxt = """ 46 self._cfgtxt = """
47 [cache] 47 [cache]
48 uri=memory://for_test 48 uri=memory://for_test
49 """ 49 """
50 self._feedcfg = []
50 self._pre_hooks = [] 51 self._pre_hooks = []
51 self._cleanup = [] 52 self._cleanup = []
52 53
53 def getFeedPath(self, name): 54 def getFeedPath(self, name):
54 return os.path.join(os.path.dirname(__file__), 55 return os.path.join(os.path.dirname(__file__),
68 69
69 def appendConfig(self, cfgtxt): 70 def appendConfig(self, cfgtxt):
70 self._cfgtxt += cfgtxt 71 self._cfgtxt += cfgtxt
71 return self 72 return self
72 73
74 def appendFeedConfig(self, feed_name, feed_url):
75 self._feedcfg.append((feed_name, feed_url))
76 return self
77
78 def setFeedConfig(self, feed_name, feed_url):
79 self._feedcfg = []
80 return self.appendFeedConfig(feed_name, feed_url)
81
73 def appendSiloConfig(self, silo_name, silo_type, **options): 82 def appendSiloConfig(self, silo_name, silo_type, **options):
74 cfgtxt = '[silo:%s]\n' % silo_name 83 cfgtxt = '[silo:%s]\n' % silo_name
75 cfgtxt += 'type=%s\n' % silo_type 84 cfgtxt += 'type=%s\n' % silo_type
76 if options is not None: 85 if options is not None:
77 for n, v in options.items(): 86 for n, v in options.items():
81 def preExecHook(self, hook): 90 def preExecHook(self, hook):
82 self._pre_hooks.append(hook) 91 self._pre_hooks.append(hook)
83 92
84 def run(self, *args): 93 def run(self, *args):
85 pre_args = [] 94 pre_args = []
86 if self._cfgtxt: 95 if self._cfgtxt or self._feedcfg:
96 cfgtxt = self._cfgtxt
97 cfgtxt += '\n\n[urls]\n'
98 for n, u in self._feedcfg:
99 cfgtxt += '%s=%s\n' % (n, u)
100
87 tmpfd, tmpcfg = tempfile.mkstemp() 101 tmpfd, tmpcfg = tempfile.mkstemp()
88 print("Creating temporary configuration file: %s" % tmpcfg) 102 print("Creating temporary configuration file: %s" % tmpcfg)
89 with os.fdopen(tmpfd, 'w') as tmpfp: 103 with os.fdopen(tmpfd, 'w') as tmpfp:
90 tmpfp.write(self._cfgtxt) 104 tmpfp.write(cfgtxt)
91 self._cleanup.append(tmpcfg) 105 self._cleanup.append(tmpcfg)
92 pre_args = ['-c', tmpcfg] 106 pre_args = ['-c', tmpcfg]
93 107
94 captured = io.StringIO() 108 captured = io.StringIO()
95 handler = logging.StreamHandler(captured) 109 handler = logging.StreamHandler(captured)
122 136
123 silorider_logger.removeHandler(handler) 137 silorider_logger.removeHandler(handler)
124 138
125 print("Cleaning %d temporary files." % len(self._cleanup)) 139 print("Cleaning %d temporary files." % len(self._cleanup))
126 for tmpname in self._cleanup: 140 for tmpname in self._cleanup:
127 os.remove(tmpname) 141 try:
142 os.remove(tmpname)
143 except FileNotFoundError:
144 pass
128 145
129 return main_ctx, main_res 146 return main_ctx, main_res
130 147
131 148
132 @pytest.fixture 149 @pytest.fixture