mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-04 22:40:29 +03:00
Refactor TestCase files into python modules
Convert all TestCase files into standard python modules to be run and discovered by unittest.
This commit is contained in:
parent
4d6682bc70
commit
7ff32bc4b0
34 changed files with 471 additions and 1260 deletions
|
|
@ -1,104 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# http://www.drdobbs.com/testing/unit-testing-with-python/240165163
|
||||
|
||||
import inspect
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from git import Repo
|
||||
|
||||
localmodule = os.path.realpath(
|
||||
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
|
||||
)
|
||||
print('localmodule: ' + localmodule)
|
||||
if localmodule not in sys.path:
|
||||
sys.path.insert(0, localmodule)
|
||||
|
||||
import fdroidserver.build
|
||||
import fdroidserver.common
|
||||
import fdroidserver.metadata
|
||||
import fdroidserver.scanner
|
||||
from testcommon import mkdtemp, parse_args_for_test
|
||||
|
||||
|
||||
class VCSTest(unittest.TestCase):
|
||||
"""For some reason the VCS classes are in fdroidserver/common.py"""
|
||||
|
||||
def setUp(self):
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
self.basedir = os.path.join(localmodule, 'tests')
|
||||
os.chdir(self.basedir)
|
||||
self._td = mkdtemp()
|
||||
self.testdir = self._td.name
|
||||
|
||||
def tearDown(self):
|
||||
self._td.cleanup()
|
||||
os.chdir(self.basedir)
|
||||
|
||||
def test_remote_set_head_can_fail(self):
|
||||
os.chdir(self.testdir)
|
||||
# First create an upstream repo with one commit
|
||||
upstream_repo = Repo.init("upstream_repo")
|
||||
with open(upstream_repo.working_dir + "/file", 'w') as f:
|
||||
f.write("Hello World!")
|
||||
upstream_repo.index.add([upstream_repo.working_dir + "/file"])
|
||||
upstream_repo.index.commit("initial commit")
|
||||
commitid = upstream_repo.head.commit.hexsha
|
||||
|
||||
# Now clone it once manually, like gitlab runner gitlab-runner sets up a repo during CI
|
||||
clone1 = Repo.init("clone1")
|
||||
clone1.create_remote("upstream", "file://" + upstream_repo.working_dir)
|
||||
clone1.remote("upstream").fetch()
|
||||
clone1.head.reference = clone1.commit(commitid)
|
||||
clone1.head.reset(index=True, working_tree=True)
|
||||
self.assertTrue(clone1.head.is_detached)
|
||||
|
||||
# and now we want to use this clone as a source repo for fdroid build
|
||||
config = {}
|
||||
os.mkdir("build")
|
||||
config['sdk_path'] = 'MOCKPATH'
|
||||
config['ndk_paths'] = {'r10d': os.getenv('ANDROID_NDK_HOME')}
|
||||
config['java_paths'] = {'fake': 'fake'}
|
||||
fdroidserver.common.config = config
|
||||
app = fdroidserver.metadata.App()
|
||||
app.RepoType = 'git'
|
||||
app.Repo = clone1.working_dir
|
||||
app.id = 'com.gpl.rpg.AndorsTrail'
|
||||
build = fdroidserver.metadata.Build()
|
||||
build.commit = commitid
|
||||
build.androidupdate = ['no']
|
||||
vcs, build_dir = fdroidserver.common.setup_vcs(app)
|
||||
# force an init of the repo, the remote head error only occurs on the second gotorevision call
|
||||
vcs.gotorevision(build.commit)
|
||||
fdroidserver.common.prepare_source(
|
||||
vcs,
|
||||
app,
|
||||
build,
|
||||
build_dir=build_dir,
|
||||
srclib_dir="ignore",
|
||||
extlib_dir="ignore",
|
||||
)
|
||||
self.assertTrue(os.path.isfile("build/com.gpl.rpg.AndorsTrail/file"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.chdir(os.path.dirname(__file__))
|
||||
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"-v",
|
||||
"--verbose",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
parse_args_for_test(parser, sys.argv)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(VCSTest))
|
||||
unittest.main(failfast=False)
|
||||
Loading…
Add table
Add a link
Reference in a new issue