@@ -120,11 +120,12 @@ def testWhoisPythonFromStaticTestData(
120120 verbose : bool = False ,
121121) -> str :
122122 domain = "." .join (dl )
123-
124- pathToTestFile = f"./testdata /{ domain } /input"
123+ testDir = os . getenv ( "TEST_WHOIS_PYTHON" )
124+ pathToTestFile = f"{ testDir } /{ domain } /input"
125125 if os .path .exists (pathToTestFile ):
126- with open (pathToTestFile , mode = "r" ) as f :
127- return f .read ()
126+ with open (pathToTestFile , mode = "rb" ) as f : # switch to binary mode as that is what Popen uses
127+ # make sure the data is treated exactly the same as the output of Popen
128+ return f .read ().decode (errors = "ignore" )
128129
129130 raise WhoisCommandFailed ("" )
130131
@@ -135,7 +136,7 @@ def _do_whois_query(
135136 server : Optional [str ] = None ,
136137 verbose : bool = False ,
137138) -> str :
138- # TODO: if getenv[TEST_WHOIS_PYTON] fake whois by reading static data from a file
139+ # if getenv[TEST_WHOIS_PYTON] fake whois by reading static data from a file
139140 # this wasy we can actually implemnt a test run with known data in and expected data out
140141 if os .getenv ("TEST_WHOIS_PYTHON" ):
141142 return testWhoisPythonFromStaticTestData (dl , ignore_returncode , server , verbose )
@@ -150,7 +151,6 @@ def _do_whois_query(
150151 env = {"LANG" : "en" } if dl [- 1 ] in ".jp" else None ,
151152 )
152153
153- # print(p.stdout.read()+' '+p.stderr.read())
154154 r = p .communicate ()[0 ].decode (errors = "ignore" )
155155 if ignore_returncode is False and p .returncode not in [0 , 1 ]:
156156 raise WhoisCommandFailed (r )
0 commit comments