291 |
291 |
292 def test_ccplugin_modname(self): |
292 def test_ccplugin_modname(self): |
293 self.config.load_cwctl_plugins() |
293 self.config.load_cwctl_plugins() |
294 self.assertIn('cubes.mycube.ccplugin', sys.modules, sorted(sys.modules)) |
294 self.assertIn('cubes.mycube.ccplugin', sys.modules, sorted(sys.modules)) |
295 self.assertNotIn('cubicweb_mycube.ccplugin', sys.modules, sorted(sys.modules)) |
295 self.assertNotIn('cubicweb_mycube.ccplugin', sys.modules, sorted(sys.modules)) |
296 |
|
297 |
|
298 class FindPrefixTC(unittest.TestCase): |
|
299 |
|
300 def make_dirs(self, basedir, *args): |
|
301 path = join(basedir, *args) |
|
302 if not os.path.exists(path): |
|
303 os.makedirs(path) |
|
304 return path |
|
305 |
|
306 def make_file(self, basedir, *args): |
|
307 self.make_dirs(basedir, *args[:-1]) |
|
308 file_path = join(basedir, *args) |
|
309 with open(file_path, 'w') as f: |
|
310 f.write('""" None """') |
|
311 return file_path |
|
312 |
|
313 def test_samedir(self): |
|
314 with TemporaryDirectory() as prefix: |
|
315 self.make_dirs(prefix, 'share', 'cubicweb') |
|
316 self.assertEqual(_find_prefix(prefix), prefix) |
|
317 |
|
318 def test_samedir_filepath(self): |
|
319 with TemporaryDirectory() as prefix: |
|
320 self.make_dirs(prefix, 'share', 'cubicweb') |
|
321 file_path = self.make_file(prefix, 'bob.py') |
|
322 self.assertEqual(_find_prefix(file_path), prefix) |
|
323 |
|
324 def test_dir_inside_prefix(self): |
|
325 with TemporaryDirectory() as prefix: |
|
326 self.make_dirs(prefix, 'share', 'cubicweb') |
|
327 dir_path = self.make_dirs(prefix, 'bob') |
|
328 self.assertEqual(_find_prefix(dir_path), prefix) |
|
329 |
|
330 def test_file_in_dir_inside_prefix(self): |
|
331 with TemporaryDirectory() as prefix: |
|
332 self.make_dirs(prefix, 'share', 'cubicweb') |
|
333 file_path = self.make_file(prefix, 'bob', 'toto.py') |
|
334 self.assertEqual(_find_prefix(file_path), prefix) |
|
335 |
|
336 def test_file_in_deeper_dir_inside_prefix(self): |
|
337 with TemporaryDirectory() as prefix: |
|
338 self.make_dirs(prefix, 'share', 'cubicweb') |
|
339 file_path = self.make_file(prefix, 'bob', 'pyves', 'alain', |
|
340 'adim', 'syt', 'toto.py') |
|
341 self.assertEqual(_find_prefix(file_path), prefix) |
|
342 |
|
343 def test_multiple_candidate_prefix(self): |
|
344 with TemporaryDirectory() as tempdir: |
|
345 self.make_dirs(tempdir, 'share', 'cubicweb') |
|
346 prefix = self.make_dirs(tempdir, 'bob') |
|
347 self.make_dirs(prefix, 'share', 'cubicweb') |
|
348 file_path = self.make_file(prefix, 'pyves', 'alain', |
|
349 'adim', 'syt', 'toto.py') |
|
350 self.assertEqual(_find_prefix(file_path), prefix) |
|
351 |
|
352 def test_sister_candidate_prefix(self): |
|
353 with TemporaryDirectory() as prefix: |
|
354 self.make_dirs(prefix, 'share', 'cubicweb') |
|
355 self.make_dirs(prefix, 'bob', 'share', 'cubicweb') |
|
356 file_path = self.make_file(prefix, 'bell', 'toto.py') |
|
357 self.assertEqual(_find_prefix(file_path), prefix) |
|
358 |
|
359 def test_multiple_parent_candidate_prefix(self): |
|
360 with TemporaryDirectory() as tempdir: |
|
361 self.make_dirs(tempdir, 'share', 'cubicweb') |
|
362 prefix = self.make_dirs(tempdir, 'share', 'cubicweb', 'bob') |
|
363 self.make_dirs(tempdir, 'share', 'cubicweb', 'bob', 'share', |
|
364 'cubicweb') |
|
365 file_path = self.make_file(tempdir, 'share', 'cubicweb', 'bob', |
|
366 'pyves', 'alain', 'adim', 'syt', |
|
367 'toto.py') |
|
368 self.assertEqual(_find_prefix(file_path), prefix) |
|
369 |
|
370 def test_upper_candidate_prefix(self): |
|
371 with TemporaryDirectory() as prefix: |
|
372 self.make_dirs(prefix, 'share', 'cubicweb') |
|
373 self.make_dirs(prefix, 'bell', 'bob', 'share', 'cubicweb') |
|
374 file_path = self.make_file(prefix, 'bell', 'toto.py') |
|
375 self.assertEqual(_find_prefix(file_path), prefix) |
|
376 |
|
377 def test_no_prefix(self): |
|
378 with TemporaryDirectory() as prefix: |
|
379 self.assertEqual(_find_prefix(prefix), sys.prefix) |
|
380 |
|
381 def test_virtualenv(self): |
|
382 venv = os.environ.get('VIRTUAL_ENV') |
|
383 try: |
|
384 with TemporaryDirectory() as prefix: |
|
385 os.environ['VIRTUAL_ENV'] = prefix |
|
386 self.make_dirs(prefix, 'share', 'cubicweb') |
|
387 self.assertEqual(_find_prefix(), prefix) |
|
388 finally: |
|
389 if venv: |
|
390 os.environ['VIRTUAL_ENV'] = venv |
|
391 |
296 |
392 |
297 |
393 class ModnamesTC(unittest.TestCase): |
298 class ModnamesTC(unittest.TestCase): |
394 |
299 |
395 @templibdir |
300 @templibdir |