tests: use standard dir setup so all tests start in same dir

This commit is contained in:
Hans-Christoph Steiner 2017-11-30 10:14:38 +01:00
parent 3ff4b656c6
commit 5b22ff7dc6
6 changed files with 96 additions and 97 deletions

View file

@ -4,6 +4,7 @@
import glob
import inspect
import logging
import optparse
import os
import random
@ -26,15 +27,20 @@ import fdroidserver.metadata
class MetadataTest(unittest.TestCase):
'''fdroidserver/metadata.py'''
def setUp(self):
logging.basicConfig(level=logging.DEBUG)
self.basedir = os.path.join(localmodule, 'tests')
self.tmpdir = os.path.abspath(os.path.join(self.basedir, '..', '.testfiles'))
if not os.path.exists(self.tmpdir):
os.makedirs(self.tmpdir)
os.chdir(self.basedir)
def test_read_metadata(self):
def _build_yaml_representer(dumper, data):
'''Creates a YAML representation of a Build instance'''
return dumper.represent_dict(data)
testsdir = os.path.dirname(__file__)
os.chdir(testsdir)
self.maxDiff = None
# these need to be set to prevent code running on None, only
@ -61,12 +67,7 @@ class MetadataTest(unittest.TestCase):
# yaml.dump(frommeta, f, default_flow_style=False)
def test_rewrite_yaml_fakeotaupdate(self):
# setup/reset test dir if necessary and setup params
tmpdir = os.path.join(os.path.dirname(__file__), '..', '.testfiles')
if not os.path.exists(tmpdir):
os.makedirs(tmpdir)
testdir = tempfile.mkdtemp(prefix='test_rewrite_metadata_', dir=tmpdir)
testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
fdroidserver.common.config = {'accepted_formats': ['txt', 'yml']}
# rewrite metadata
@ -82,12 +83,7 @@ class MetadataTest(unittest.TestCase):
self.assertEqual(result.read(), orig.read())
def test_rewrite_yaml_fdroidclient(self):
# setup/reset test dir if necessary and setup params
tmpdir = os.path.join(os.path.dirname(__file__), '..', '.testfiles')
if not os.path.exists(tmpdir):
os.makedirs(tmpdir)
testdir = tempfile.mkdtemp(prefix='test_rewrite_metadata_', dir=tmpdir)
testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
fdroidserver.common.config = {'accepted_formats': ['txt', 'yml']}
# rewrite metadata
@ -103,12 +99,7 @@ class MetadataTest(unittest.TestCase):
self.assertEqual(result.read(), orig.read())
def test_rewrite_yaml_special_build_params(self):
# setup/reset test dir if necessary and setup params
tmpdir = os.path.join(os.path.dirname(__file__), '..', '.testfiles')
if not os.path.exists(tmpdir):
os.makedirs(tmpdir)
testdir = tempfile.mkdtemp(prefix='test_rewrite_metadata_', dir=tmpdir)
testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
fdroidserver.common.config = {'accepted_formats': ['txt', 'yml']}
# rewrite metadata
@ -124,18 +115,13 @@ class MetadataTest(unittest.TestCase):
self.assertEqual(result.read(), orig.read())
def test_read_metadata_sort_by_time(self):
# setup/reset test dir if necessary and setup params
testbasedir = os.path.dirname(__file__)
tmpdir = os.path.join(testbasedir, '..', '.testfiles')
if not os.path.exists(tmpdir):
os.makedirs(tmpdir)
testdir = tempfile.mkdtemp(prefix='test_read_metadata_sort_by_time_', dir=tmpdir)
testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
metadatadir = os.path.join(testdir, 'metadata')
os.makedirs(metadatadir)
fdroidserver.common.config = {'accepted_formats': ['txt']}
randomlist = []
randomapps = glob.glob(os.path.join(testbasedir, 'metadata', '*.txt'))
randomapps = glob.glob(os.path.join(self.basedir, 'metadata', '*.txt'))
random.shuffle(randomapps)
i = 1
for f in randomapps: