move translate_path from paths.py to util.py
So translate_path can be used in util.py, or it will result in circular import error. Signed-off-by: Qixiang Wan <qwan@redhat.com>
This commit is contained in:
parent
d1763fca7e
commit
0f508e2228
13 changed files with 54 additions and 71 deletions
|
|
@ -13,7 +13,7 @@ from pungi.notifier import PungiNotifier
|
|||
|
||||
|
||||
class TestNotifier(unittest.TestCase):
|
||||
@mock.patch('pungi.paths.translate_path')
|
||||
@mock.patch('pungi.util.translate_path')
|
||||
@mock.patch('kobo.shortcuts.run')
|
||||
def test_invokes_script(self, run, translate_path):
|
||||
compose = mock.Mock(
|
||||
|
|
@ -73,7 +73,7 @@ class TestNotifier(unittest.TestCase):
|
|||
n.send('cmd', foo='bar', baz='quux')
|
||||
self.assertFalse(run.called)
|
||||
|
||||
@mock.patch('pungi.paths.translate_path')
|
||||
@mock.patch('pungi.util.translate_path')
|
||||
@mock.patch('kobo.shortcuts.run')
|
||||
def test_logs_warning_on_failure(self, run, translate_path):
|
||||
compose = mock.Mock(
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
#!/usr/bin/env python2
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import mock
|
||||
import unittest
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
||||
|
||||
from pungi import paths
|
||||
|
||||
|
||||
class TranslatePathTestCase(unittest.TestCase):
|
||||
def test_does_nothing_without_config(self):
|
||||
compose = mock.Mock(conf={'translate_paths': []})
|
||||
ret = paths.translate_path(compose, '/mnt/koji/compose/rawhide/XYZ')
|
||||
self.assertEqual(ret, '/mnt/koji/compose/rawhide/XYZ')
|
||||
|
||||
def test_translates_prefix(self):
|
||||
compose = mock.Mock(conf={
|
||||
'translate_paths': [('/mnt/koji', 'http://example.com')]
|
||||
})
|
||||
ret = paths.translate_path(compose, '/mnt/koji/compose/rawhide/XYZ')
|
||||
self.assertEqual(ret, 'http://example.com/compose/rawhide/XYZ')
|
||||
|
||||
def test_does_not_translate_not_matching(self):
|
||||
compose = mock.Mock(conf={
|
||||
'translate_paths': [('/mnt/koji', 'http://example.com')]
|
||||
})
|
||||
ret = paths.translate_path(compose, '/mnt/fedora_koji/compose/rawhide/XYZ')
|
||||
self.assertEqual(ret, '/mnt/fedora_koji/compose/rawhide/XYZ')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
@ -519,5 +519,26 @@ class TestUnmountCmd(unittest.TestCase):
|
|||
'lsof +D /path', 1, 'lsof output')])
|
||||
|
||||
|
||||
class TranslatePathTestCase(unittest.TestCase):
|
||||
def test_does_nothing_without_config(self):
|
||||
compose = mock.Mock(conf={'translate_paths': []})
|
||||
ret = util.translate_path(compose, '/mnt/koji/compose/rawhide/XYZ')
|
||||
self.assertEqual(ret, '/mnt/koji/compose/rawhide/XYZ')
|
||||
|
||||
def test_translates_prefix(self):
|
||||
compose = mock.Mock(conf={
|
||||
'translate_paths': [('/mnt/koji', 'http://example.com')]
|
||||
})
|
||||
ret = util.translate_path(compose, '/mnt/koji/compose/rawhide/XYZ')
|
||||
self.assertEqual(ret, 'http://example.com/compose/rawhide/XYZ')
|
||||
|
||||
def test_does_not_translate_not_matching(self):
|
||||
compose = mock.Mock(conf={
|
||||
'translate_paths': [('/mnt/koji', 'http://example.com')]
|
||||
})
|
||||
ret = util.translate_path(compose, '/mnt/fedora_koji/compose/rawhide/XYZ')
|
||||
self.assertEqual(ret, '/mnt/fedora_koji/compose/rawhide/XYZ')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue