forked from operatorequals/httpimport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
56 lines (40 loc) · 1.43 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
try :
import SimpleHTTPServer
import SocketServer
except ImportError:
import http.server
import socketserver
import sys
from threading import Thread
from time import sleep
import httpimport
import unittest
from random import randint
class Test( unittest.TestCase ) :
def test_simple_HTTP(self) :
# ============== Setting up an HTTP server at 'http://localhost:8001/' in current directory
try :
PORT = int(sys.argv[1])
except :
PORT = randint(1025, 65535)
try :
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
except :
Handler = http.server.SimpleHTTPRequestHandler
httpd = socketserver.TCPServer(("", PORT), Handler)
print ("Serving at port %d" % PORT)
http_thread = Thread( target = httpd.serve_forever, )
http_thread.daemon = True
# ============== Starting the HTTP server
http_thread.start()
# ============== Wait until HTTP server is ready
sleep(1)
httpimport.INSECURE = True
with httpimport.remote_repo(['test_package'], base_url = 'http://localhost:%d/' % PORT) :
from test_package import module1
self.assertTrue(module1.dummy_str) # If this point is reached then the module1 is imported succesfully!
def test_github_repo(self) :
with httpimport.github_repo( 'operatorequals', 'covertutils', ) :
import covertutils
self.assertTrue(covertutils.__author__) # If this point is reached then the module1 is imported succesfully!