Skip to content

Commit 9d01998

Browse files
committed
fix: use absolute imports
1 parent 6d5db62 commit 9d01998

File tree

8 files changed

+33
-108
lines changed

8 files changed

+33
-108
lines changed

Pilot/__init__.py

Whitespace-only changes.

Pilot/dirac-pilot.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,13 @@
2424
import time
2525
from io import StringIO
2626

27-
try:
28-
from Pilot.pilotTools import (
29-
Logger,
30-
PilotParams,
31-
RemoteLogger,
32-
getCommand,
33-
pythonPathCheck,
34-
)
35-
except ModuleNotFoundError:
36-
from pilotTools import (
37-
Logger,
38-
PilotParams,
39-
RemoteLogger,
40-
getCommand,
41-
pythonPathCheck,
42-
)
27+
from pilotTools import (
28+
Logger,
29+
PilotParams,
30+
RemoteLogger,
31+
getCommand,
32+
pythonPathCheck,
33+
)
4334

4435
############################
4536

Pilot/pilotCommands.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,13 @@ def __init__(self, pilotParams):
3030
from http.client import HTTPSConnection
3131
from shlex import quote
3232

33-
try:
34-
from Pilot.pilotTools import (
35-
CommandBase,
36-
getSubmitterInfo,
37-
retrieveUrlTimeout,
38-
safe_listdir,
39-
sendMessage,
40-
)
41-
except ModuleNotFoundError:
42-
from pilotTools import (
43-
CommandBase,
44-
getSubmitterInfo,
45-
retrieveUrlTimeout,
46-
safe_listdir,
47-
sendMessage,
48-
)
33+
from pilotTools import (
34+
CommandBase,
35+
getSubmitterInfo,
36+
retrieveUrlTimeout,
37+
safe_listdir,
38+
sendMessage,
39+
)
4940

5041
############################
5142

Pilot/pilotTools.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@
2222
from urllib.parse import urlencode
2323
from urllib.request import urlopen
2424

25-
try:
26-
from Pilot.proxyTools import getVO
27-
except ModuleNotFoundError:
28-
from proxyTools import getVO
25+
from proxyTools import getVO
2926

3027
# Utilities functions
3128

Pilot/tests/Test_Pilot.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
# imports
1111
import unittest
1212

13-
try:
14-
from Pilot.pilotCommands import CheckWorkerNode, ConfigureSite, NagiosProbes
15-
from Pilot.pilotTools import PilotParams
16-
except ModuleNotFoundError:
17-
from pilotCommands import CheckWorkerNode, ConfigureSite, NagiosProbes
18-
from pilotTools import PilotParams
13+
sys.path.insert(0, os.getcwd() + "/Pilot")
14+
15+
from pilotCommands import CheckWorkerNode, ConfigureSite, NagiosProbes
16+
from pilotTools import PilotParams
1917

2018

2119
class PilotTestCase(unittest.TestCase):

Pilot/tests/Test_proxyTools.py

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
21
import os
3-
import shlex
42
import shutil
5-
import subprocess
63
import sys
74
import unittest
85
from unittest.mock import patch
96

10-
try:
11-
from Pilot.proxyTools import getVO, parseASN1
12-
except ModuleNotFoundError:
13-
from proxyTools import getVO, parseASN1
7+
sys.path.insert(0, os.getcwd() + "/Pilot")
8+
9+
from proxyTools import getVO, parseASN1
10+
1411

1512
class TestProxyTools(unittest.TestCase):
1613
def test_getVO(self):
@@ -23,7 +20,7 @@ def test_getVO(self):
2320
os.remove(cert)
2421
self.assertEqual(vo, "fakevo")
2522

26-
@patch("Pilot.proxyTools.Popen")
23+
@patch("proxyTools.Popen")
2724
def test_getVOPopenFails(self, popenMock):
2825
"""
2926
Check if an exception is raised when Popen return code is not 0.
@@ -51,7 +48,7 @@ def test_getVOPopenFails(self, popenMock):
5148
getVO(data)
5249
self.assertEqual(str(exc.exception), msg)
5350

54-
@patch("Pilot.proxyTools.Popen")
51+
@patch("proxyTools.Popen")
5552
def test_parseASN1Fails(self, popenMock):
5653
"""Should raise an exception when Popen return code is !=0"""
5754

@@ -84,46 +81,7 @@ def __createFakeProxy(self, proxyFile):
8481
"""
8582
Create a fake proxy locally.
8683
"""
87-
8884
basedir = os.path.dirname(__file__)
89-
shutil.copy(basedir + "/certs/user/userkey.pem", basedir + "/certs/user/userkey400.pem")
90-
os.chmod(basedir + "/certs/user/userkey400.pem", 0o400)
91-
ret = self.createFakeProxy(
92-
basedir + "/certs/user/usercert.pem",
93-
basedir + "/certs/user/userkey400.pem",
94-
"fakeserver.cern.ch:15000",
95-
"fakevo",
96-
basedir + "/certs//host/hostcert.pem",
97-
basedir + "/certs/host/hostkey.pem",
98-
basedir + "/certs/ca",
99-
proxyFile,
100-
)
101-
os.remove(basedir + "/certs/user/userkey400.pem")
102-
return ret
103-
104-
def createFakeProxy(self, usercert, userkey, serverURI, vo, hostcert, hostkey, CACertDir, proxyfile):
105-
"""
106-
voms-proxy-fake --cert usercert.pem
107-
--key userkey.pem
108-
-rfc
109-
-fqan "/fakevo/Role=user/Capability=NULL"
110-
-uri fakeserver.cern.ch:15000
111-
-voms fakevo
112-
-hostcert hostcert.pem
113-
-hostkey hostkey.pem
114-
-certdir ca
115-
"""
116-
opt = (
117-
'--cert %s --key %s -rfc -fqan "/fakevo/Role=user/Capability=NULL" -uri %s -voms %s -hostcert %s'
118-
" -hostkey %s -certdir %s -out %s"
119-
% (usercert, userkey, serverURI, vo, hostcert, hostkey, CACertDir, proxyfile)
120-
)
121-
proc = subprocess.Popen(
122-
shlex.split("voms-proxy-fake " + opt),
123-
bufsize=1,
124-
stdout=sys.stdout,
125-
stderr=sys.stderr,
126-
universal_newlines=True,
127-
)
128-
proc.communicate()
129-
return proc.returncode
85+
shutil.copy(basedir + "/certs/voms/proxy.pem", proxyFile)
86+
return 0
87+

Pilot/tests/Test_simplePilotLogger.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
import os
55
import random
66
import string
7+
import sys
78
import tempfile
89
import unittest
910
from unittest.mock import patch
1011

11-
try:
12-
from Pilot.pilotTools import CommandBase, Logger, PilotParams
13-
except ModuleNotFoundError:
14-
from pilotTools import CommandBase, Logger, PilotParams
12+
sys.path.insert(0, os.getcwd() + "/Pilot")
13+
14+
from pilotTools import CommandBase, Logger, PilotParams
15+
1516

1617
class TestPilotParams(unittest.TestCase):
1718
@patch("sys.argv")

Untitled

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)