Skip to content
This repository has been archived by the owner on Sep 14, 2018. It is now read-only.

Commit

Permalink
Partial fix for #917 (#1466)
Browse files Browse the repository at this point in the history
* Partial fix for #917

* Put generated DLLs in the temp folder
  • Loading branch information
slozier authored and slide committed Oct 15, 2016
1 parent 473fc03 commit b31b0ad
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 77 deletions.
31 changes: 4 additions & 27 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,11 @@ Solutions/TestResults/
Runtime/Samples/Hosting/Scenarios/bin/

# TODO - testing scripts should not create these files
debug.log
External.LCA_RESTRICTED/Languages/IronPython/27/Lib/@test_*
External.LCA_RESTRICTED/Languages/IronPython/27/Lib/lib2to3/Grammar2.9.9.alpha.0.pickle
External.LCA_RESTRICTED/Languages/IronPython/27/Lib/lib2to3/PatternGrammar2.9.9.alpha.0.pickle
Languages/IronPython/Tests/ImportTestDir/
Languages/IronPython/Tests/InheritanceTypes.dll
Languages/IronPython/Tests/OutterDir/
Languages/IronPython/Tests/another.py
Languages/IronPython/Tests/cached_type_dll.dll
Languages/IronPython/Tests/cp7007/
Languages/IronPython/Tests/finaltest.dll
Languages/IronPython/Tests/foo
Languages/IronPython/Tests/imfpstart.tpy
Languages/IronPython/Tests/impcp13736.py
Languages/IronPython/Tests/impmodfrmpkg/
Languages/IronPython/Tests/onlyread.tmp
Languages/IronPython/Tests/onlywrite.tmp
Languages/IronPython/Tests/tempFile1.tpy
Languages/IronPython/Tests/temp_syspath_none.py
Languages/IronPython/Tests/test.dll
Languages/IronPython/Tests/test.pyil
Languages/IronPython/Tests/test.xaml
Languages/IronPython/Tests/testfile.tmp
Languages/IronPython/Tests/testilcode.dll
Languages/IronPython/Tests/the_dir/
Languages/IronPython/Tests/tmp*
Languages/IronPython/Tests/tempfile.txt
Languages/IronPython/Tests/vbproptest0.*.dll

# created by CPython tests
External.LCA_RESTRICTED/Languages/IronPython/27/Lib/lib2to3/Grammar*.pickle
External.LCA_RESTRICTED/Languages/IronPython/27/Lib/lib2to3/PatternGrammar*.pickle

# created by side by side tests
Languages/IronPython/Tests/compat/*.log
Expand Down
23 changes: 17 additions & 6 deletions Languages/IronPython/IronPython/Lib/iptest/file_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,17 @@ def filecopy(oldpath, newpath):
if of: of.close()
if nf: nf.close()

def clean_directory(path):
def clean_directory(path, remove=False):
for f in os.listdir(path):
try:
os.unlink(path_combine(path, f))
except:
pass
if remove:
try:
os.rmdir(path)
except:
pass

def get_directory_name(file):
file = fullpath(file)
Expand Down Expand Up @@ -198,14 +203,20 @@ def get_mod_names(filename):

return ret_val



def delete_all_f(module_name):
def delete_all_f(module_name, remove_folders=False):
module = sys.modules[module_name]
folders = {}
for x in dir(module):
if x.startswith('_f_'):
fn = getattr(module, x)
if isinstance(fn, str):
try: os.unlink(fn)
try:
os.unlink(fn)
name = os.path.dirname(fn)
if os.path.isdir(name):
folders[name] = None
except: pass

if remove_folders:
for x in sorted(folders.iterkeys(), reverse=True):
try: os.rmdir(x)
except: pass
2 changes: 1 addition & 1 deletion Languages/IronPython/IronPython/Runtime/PythonContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ public override ScriptCode CompileSourceCode(SourceUnit/*!*/ sourceUnit, Compile
ContractUtils.RequiresNotNull(defaultEncoding, "defaultEncoding");
ContractUtils.Requires(stream.CanSeek && stream.CanRead, "stream", "The stream must support seeking and reading");

// we choose ASCII by default, if the file has a Unicode pheader though
// we choose ASCII by default, if the file has a Unicode header though
// we'll automatically get it as unicode.
Encoding encoding = PythonAsciiEncoding.SourceEncoding;

Expand Down
2 changes: 1 addition & 1 deletion Languages/IronPython/Tests/compat/sbs_func_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def f3(arg0, arg1, arg2, *arg3): return "same## %s %s %s %s" % (arg0, arg1, arg2
from iptest.process_util import run_csc
run_csc("/nologo /target:library /out:sbs_library.dll sbs_library.cs")
import clr
clr.AddReferenceToFileAndPath("sbs_library.dll")
clr.AddReferenceToFile("sbs_library.dll")
from SbsTest import C
o = C()
g1 = o.M1
Expand Down
15 changes: 7 additions & 8 deletions Languages/IronPython/Tests/modules/io_related/codecs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ def test_file_encodings():
finally:
#cleanup
sys.path.remove(path_combine(os.getcwd(), "tmp_encodings"))
os.rmdir(path_combine(os.getcwd(), "tmp_encodings"))

@skip("silverlight")
@skip("netstandard") # sys.executable isn't an executable
Expand Down Expand Up @@ -548,25 +549,23 @@ def test_file_encodings_negative():
- need variations on the encoding names
'''
import sys
if is_posix:
import posix as _os
else:
import nt as _os
sys.path.append(path_combine(_os.getcwd(), "tmp_encodings"))
sys.path.append(path_combine(os.getcwd(), "tmp_encodings"))
try:
_os.mkdir(path_combine(_os.getcwd(), "tmp_encodings"))
os.mkdir(path_combine(os.getcwd(), "tmp_encodings"))
except:
pass

try:
#negative case
f = open(path_combine(_os.getcwd(), "tmp_encodings", "bad_encoding.py"), "w")
f = open(path_combine(os.getcwd(), "tmp_encodings", "bad_encoding.py"), "w")
f.write("# coding: bad")
f.close()
AssertError(SyntaxError, __import__, "bad_encoding")
os.remove(path_combine(os.getcwd(), "tmp_encodings", "bad_encoding.py"))
finally:
#cleanup
sys.path.remove(path_combine(_os.getcwd(), "tmp_encodings"))
sys.path.remove(path_combine(os.getcwd(), "tmp_encodings"))
os.rmdir(path_combine(os.getcwd(), "tmp_encodings"))

@disabled
def test_cp1214():
Expand Down
4 changes: 2 additions & 2 deletions Languages/IronPython/Tests/modules/io_related/fd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_open():
os.close(fd3)
os.close(fd4)

for i in range(1, 4):
for i in range(1, 5):
os.unlink(test_filename + str(i))

def test_write():
Expand Down Expand Up @@ -221,7 +221,7 @@ def test_pipe_fds():
os.close(w)
os.close(fd)
f.close()
for i in range(1, 2):
for i in range(1, 3):
os.unlink(test_filename + str(i))


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#####################################################################################

from iptest.assert_util import *
if is_silverlight==False:
if not is_silverlight:
from iptest.file_util import *

import marshal
Expand Down Expand Up @@ -136,6 +136,9 @@ def test_file_multiple_reads():
obj = marshal.load(f)
AreEqual(obj, {i:i})

f.close()
delete_files('tempfile.txt')

def test_string_interning():
AreEqual(marshal.dumps(['abc', 'abc'], 1), '[\x02\x00\x00\x00t\x03\x00\x00\x00abcR\x00\x00\x00\x00')
AreEqual(marshal.dumps(['abc', 'abc']), '[\x02\x00\x00\x00t\x03\x00\x00\x00abcR\x00\x00\x00\x00')
Expand Down
4 changes: 3 additions & 1 deletion Languages/IronPython/Tests/test_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,7 @@ def test_write_file():

AssertError(TypeError, f.write, inp)
f.close()


delete_files('foo')

run_test(__name__)
4 changes: 2 additions & 2 deletions Languages/IronPython/Tests/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ def __getattr__(self, name):
c.close()

try:
import nt
nt.unlink(tmpfile)
import os
os.unlink(tmpfile)
except:
pass

Expand Down
21 changes: 11 additions & 10 deletions Languages/IronPython/Tests/test_cliclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ def test_nondefault_indexers():
""")
f.close()

name = 'vbproptest%f.dll' % (r.random())
name = path_combine(testpath.temporary_dir, 'vbproptest%f.dll' % (r.random()))
x = run_vbc('/target:library vbproptest1.vb "/out:%s"' % name)
AreEqual(x, 0)

Expand Down Expand Up @@ -787,7 +787,7 @@ def test_nondefault_indexers_overloaded():
""")
f.close()

name = 'vbproptest%f.dll' % (r.random())
name = path_combine(testpath.temporary_dir, 'vbproptest%f.dll' % (r.random()))
AreEqual(run_vbc('/target:library vbproptest1.vb /out:"%s"' % name), 0)

clr.AddReferenceToFileAndPath(name)
Expand Down Expand Up @@ -1534,7 +1534,7 @@ def test_valuetype_iter():
AreEqual(it.next().Key, 'a')
AreEqual(it.next().Key, 'b')

@skip("silverlight", "posix", "netstandard")
@skip("silverlight", "posix")
def test_abstract_class_no_interface_impl():
# this can't be defined in C# or VB, it's a class which is
# abstract and therefore doesn't implement the interface method
Expand Down Expand Up @@ -1613,13 +1613,15 @@ def test_abstract_class_no_interface_impl():
} // end of class foo
"""
from iptest.process_util import run_ilasm
f = file('testilcode.il', 'w+')
testilcode = path_combine(testpath.temporary_dir, 'testilcode.il')

f = file(testilcode, 'w+')
f.write(ilcode)
f.close()
try:
run_ilasm("/dll testilcode.il")
run_ilasm("/dll " + testilcode)

clr.AddReference('testilcode.dll')
clr.AddReferenceToFileAndPath(path_combine(testpath.temporary_dir, 'testilcode.dll'))
import AbstractILTest

class x(AbstractILTest):
Expand All @@ -1629,7 +1631,7 @@ def Baz(self): return "42"
AreEqual(AbstractILTest.Helper(a), "42")
finally:
import os
os.unlink('testilcode.il')
os.unlink(testilcode)

def test_field_assign():
"""assign to an instance field through the type"""
Expand Down Expand Up @@ -1852,8 +1854,8 @@ class MyXamlRootObject(XamlTestObject):
inp.Dispose()

finally:
#os.unlink('test.xaml')
pass
import os
os.unlink('test.xaml')


@skip("silverlight")
Expand Down Expand Up @@ -2016,4 +2018,3 @@ def __init__(self, cat, id, qtyOnHand ):

#--MAIN------------------------------------------------------------------------
run_test(__name__)

5 changes: 5 additions & 0 deletions Languages/IronPython/Tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def test_sanity():
AssertError(ValueError, f.write, "abc")
AssertError(ValueError, f.writelines, ["abc","def"])

os.unlink("onlyread.tmp")
os.unlink("onlywrite.tmp")

###

# The name of a temporary test data file that will be used for the following
Expand Down Expand Up @@ -613,6 +616,8 @@ def test_newline(norm, mode):
test_newline(norm, "r")
test_newline(unnorm, "rb")

os.unlink("testfile.tmp")

def test_creation():
f = file.__new__(file, None)
Assert(repr(f).startswith("<closed file '<uninitialized file>', mode '<uninitialized file>' at"))
Expand Down
15 changes: 11 additions & 4 deletions Languages/IronPython/Tests/test_imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def test_imp_in_exec():
exec 'from System import *'
Assert('Int32' in dir())

delete_files(_f_imfp_start)
clean_directory(path_combine(testpath.public_testdir, _imfp), remove=True)

def test_imp_basic():
magic = imp.get_magic()
suffixes = imp.get_suffixes()
Expand All @@ -92,7 +95,7 @@ def test_imp_basic():
AreEqual(len(suffix), 3)
Assert((".py", "U", 1) in suffixes)

if is_silverlight==False:
if not is_silverlight:
_testdir = "ImpTest"
_imptestdir = path_combine(testpath.public_testdir, _testdir)
_f_init = path_combine(_imptestdir, "__init__.py")
Expand Down Expand Up @@ -358,6 +361,7 @@ def test_sys_path_none_userpy():

finally:
sys.path = prevPath
delete_files(path_combine(testpath.public_testdir, "temp_syspath_none.py"))


def test_sys_path_none_negative():
Expand Down Expand Up @@ -530,7 +534,7 @@ def test_cp7007():
AreEqual(temp_mod.called, 3.14)
finally:
sys.path.remove(path_combine(testpath.public_testdir, "cp7007"))
delete_files(strange_file_names)
clean_directory(path_combine(testpath.public_testdir, "cp7007"), remove=True)

def test_relative_control():
"""test various flavors of relative/absolute import and ensure the right
Expand Down Expand Up @@ -1073,6 +1077,9 @@ def a(self):
t = new.classobj('Test1', (getattr(module, 'Test'),), {})
i = t()
AreEqual(i.a(), 34)

moduleInfo[0].close()
delete_files(_f_imp_cp13736)

def test_import_path_seperator():
"""verify using the path seperator in a direct call will result in an ImportError"""
Expand Down Expand Up @@ -1354,5 +1361,5 @@ def test_new_builtin_modules():

#------------------------------------------------------------------------------
run_test(__name__)
if is_silverlight==False:
delete_all_f(__name__)
if not is_silverlight:
delete_all_f(__name__, remove_folders=True)
Loading

0 comments on commit b31b0ad

Please sign in to comment.