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

Commit

Permalink
Bug 965270 - [mozversion] All unit tests fail on Windows because temp…
Browse files Browse the repository at this point in the history
…file.mkstemp() keeps file open. r=ahal
  • Loading branch information
whimboo committed Feb 13, 2014
1 parent 0afd984 commit 62ca958
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
6 changes: 5 additions & 1 deletion mozversion/tests/test_b2g.py
Expand Up @@ -18,7 +18,11 @@ class SourcesTest(unittest.TestCase):

def setUp(self):
self.tempdir = tempfile.mkdtemp()
self.binary = tempfile.mkstemp(dir=self.tempdir)[1]

self.binary = os.path.join(self.tempdir, 'binary')
with open(self.binary, 'w') as f:
f.write('foobar')

with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f:
f.writelines("""[App]\nName = B2G\n""")

Expand Down
16 changes: 8 additions & 8 deletions mozversion/tests/test_binary.py
Expand Up @@ -32,38 +32,38 @@ def setUp(self):
self.cwd = os.getcwd()
self.tempdir = tempfile.mkdtemp()

self.binary = os.path.join(self.tempdir, 'binary')
with open(self.binary, 'w') as f:
f.write('foobar')

def tearDown(self):
os.chdir(self.cwd)
mozfile.remove(self.tempdir)

def test_binary(self):
binary = tempfile.mkstemp(dir=self.tempdir)[1]

with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f:
f.writelines(self.application_ini)

with open(os.path.join(self.tempdir, 'platform.ini'), 'w') as f:
f.writelines(self.platform_ini)

self._check_version(get_version(binary))
self._check_version(get_version(self.binary))

def test_binary_in_current_path(self):
with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f:
f.writelines(self.application_ini)

with open(os.path.join(self.tempdir, 'platform.ini'), 'w') as f:
f.writelines(self.platform_ini)

os.chdir(self.tempdir)
self._check_version(get_version())

def test_invalid_binary_path(self):
self.assertRaises(
IOError, get_version, os.path.join(self.tempdir, 'invalid'))
self.assertRaises(IOError, get_version,
os.path.join(self.tempdir, 'invalid'))

def test_missing_ini_files(self):
binary = tempfile.mkstemp(dir=self.tempdir)[1]
v = get_version(binary)
v = get_version(self.binary)
self.assertEqual(v, {})

def _check_version(self, version):
Expand Down
12 changes: 7 additions & 5 deletions mozversion/tests/test_sources.py
Expand Up @@ -27,6 +27,10 @@ def setUp(self):
self.cwd = os.getcwd()
self.tempdir = tempfile.mkdtemp()

self.binary = os.path.join(self.tempdir, 'binary')
with open(self.binary, 'w') as f:
f.write('foobar')

def tearDown(self):
os.chdir(self.cwd)
mozfile.remove(self.tempdir)
Expand All @@ -35,7 +39,7 @@ def test_sources(self):
with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f:
f.writelines(self.application_ini)

sources = tempfile.mkstemp(dir=self.tempdir)[1]
sources = os.path.join(self.tempdir, 'sources.xml')
with open(sources, 'w') as f:
f.writelines(self.sources_xml)

Expand All @@ -53,13 +57,11 @@ def test_sources_in_current_directory(self):
self._check_version(get_version())

def test_invalid_sources_path(self):
binary = tempfile.mkstemp(dir=self.tempdir)[1]
v = get_version(binary, os.path.join(self.tempdir, 'invalid'))
v = get_version(self.binary, os.path.join(self.tempdir, 'invalid'))
self.assertEqual(v, {})

def test_missing_sources_file(self):
binary = tempfile.mkstemp(dir=self.tempdir)[1]
v = get_version(binary)
v = get_version(self.binary)
self.assertEqual(v, {})

def _check_version(self, version):
Expand Down

0 comments on commit 62ca958

Please sign in to comment.