Make openstack_election look more like a python module
Currently the code in this repo is half modular have series of scripts. Migrate the code to be more modular. The main benefit to this is testing is easier. Testing is added in a followup patch Change-Id: Ic1262436147ecdb818ee259e2e85fca8df09d722
This commit is contained in:
parent
df4eb69e66
commit
b285d3dd9c
1
.gitignore
vendored
1
.gitignore
vendored
@ -13,3 +13,4 @@ candidates/tc.rst
|
||||
candidates/events.rst
|
||||
.projects*yaml
|
||||
.projects*.pkl
|
||||
.testrepository
|
||||
|
8
.testr.conf
Normal file
8
.testr.conf
Normal file
@ -0,0 +1,8 @@
|
||||
[DEFAULT]
|
||||
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
|
||||
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
|
||||
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-160} \
|
||||
${PYTHON:-python} -m subunit.run discover -t ./ ${OS_TEST_PATH:-./openstack_election/tests} $LISTOPT $IDOPTION
|
||||
|
||||
test_id_option=--load-list $IDFILE
|
||||
test_list_option=--list
|
0
openstack_election/__init__.py
Normal file
0
openstack_election/__init__.py
Normal file
@ -17,7 +17,7 @@ from __future__ import unicode_literals
|
||||
import datetime
|
||||
import os
|
||||
|
||||
import utils
|
||||
from openstack_election import utils
|
||||
|
||||
|
||||
# FIXME: Printing from library function isn't great.
|
0
openstack_election/cmds/__init__.py
Normal file
0
openstack_election/cmds/__init__.py
Normal file
@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
@ -17,10 +15,9 @@ from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
import check_candidacy
|
||||
import utils
|
||||
from openstack_election import check_candidacy
|
||||
from openstack_election import utils
|
||||
|
||||
|
||||
def get_reviews():
|
||||
@ -63,7 +60,3 @@ def main():
|
||||
print('[E]: %s is not a valid candidate\n\n' %
|
||||
(owner['email']))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
@ -17,10 +15,9 @@ from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
import check_candidacy
|
||||
import utils
|
||||
from openstack_election import check_candidacy
|
||||
from openstack_election import utils
|
||||
|
||||
|
||||
def main():
|
||||
@ -55,6 +52,3 @@ def main():
|
||||
else:
|
||||
print('[E]: %s is not a valid candidate\n\n' % (owner['email']))
|
||||
return 1
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
0
openstack_election/tests/__init__.py
Normal file
0
openstack_election/tests/__init__.py
Normal file
34
openstack_election/tests/test_utils.py
Normal file
34
openstack_election/tests/test_utils.py
Normal file
@ -0,0 +1,34 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import testtools
|
||||
|
||||
import openstack_election.utils
|
||||
|
||||
|
||||
class TestGerritUtils(testtools.TestCase):
|
||||
def test_candidate_files(self):
|
||||
review = {'revisions': {
|
||||
'Ifake': {
|
||||
'files': {
|
||||
'some/file': {},
|
||||
'candidates/some/file': {}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.assertEqual(openstack_election.utils.candidate_files(review),
|
||||
['candidates/some/file'])
|
19
setup.cfg
19
setup.cfg
@ -1,11 +1,28 @@
|
||||
[metadata]
|
||||
name = openstack-election
|
||||
version = 11.0
|
||||
summary = OpenStack Election Documents
|
||||
description-file = README.rst
|
||||
author = OpenStack Election Officials
|
||||
author-email = openstack-dev@lists.openstack.org
|
||||
home-page = http://www.openstack.org/
|
||||
classifier =
|
||||
Environment :: OpenStack
|
||||
Intended Audience :: Information Technology
|
||||
Intended Audience :: System Administrators
|
||||
License :: OSI Approved :: Apache Software License
|
||||
Operating System :: POSIX :: Linux
|
||||
Programming Language :: Python
|
||||
Programming Language :: Python :: 2
|
||||
Programming Language :: Python :: 2.7
|
||||
|
||||
[files]
|
||||
packages = openstack_election
|
||||
|
||||
[entry_points]
|
||||
console_scripts =
|
||||
check-all-candidacies = openstack_election.cmds.check_all_candidacies:check_reviews
|
||||
check-candidacy = openstack_election.cmds.check_candidacy:main
|
||||
|
||||
|
||||
[build_sphinx]
|
||||
all_files = 1
|
||||
|
@ -6,3 +6,7 @@ sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2 # BSD
|
||||
oslosphinx!=3.4.0,>=2.5.0 # Apache-2.0
|
||||
flake8>=2.5.4,<2.6.0 # MIT
|
||||
yamllint
|
||||
mock>=2.0 # BSD
|
||||
oslotest>=1.10.0 # Apache-2.0
|
||||
testrepository>=0.0.18 # Apache-2.0/BSD
|
||||
testresources>=0.2.4 # Apache-2.0/BSD
|
||||
|
8
tox.ini
8
tox.ini
@ -1,6 +1,6 @@
|
||||
[tox]
|
||||
envlist = docs,linters
|
||||
minversion = 1.6
|
||||
envlist = docs,linters,py34,py27
|
||||
minversion = 2.0
|
||||
skipsdist = True
|
||||
|
||||
[testenv]
|
||||
@ -9,6 +9,10 @@ install_command = pip install -U {opts} {packages}
|
||||
setenv = VIRTUAL_ENV={envdir}
|
||||
deps = -r{toxinidir}/requirements.txt
|
||||
-r{toxinidir}/test-requirements.txt
|
||||
# NOTE: If py34 fails with "db type could not be determined", delete
|
||||
# .testrepository and try again. Running py34 before py27 is OK, but not the
|
||||
# other way around. See: https://bugs.launchpad.net/testrepository/+bug/1212909
|
||||
commands = python setup.py testr --slowest --testr-args="{posargs}"
|
||||
|
||||
[testenv:linters]
|
||||
commands = yamllint events.yaml
|
||||
|
Loading…
Reference in New Issue
Block a user