Browse Source

Add unit test framework and one unit test

Add an initial unit test framework and one unit test. This way we can
ask people to add unit tests when they contribute code.

Change-Id: If52976e1992945a8e38af3cbad5b5f4389922d4c
tags/0.4.0
John L. Villalovos 1 year ago
parent
commit
4658934d22
8 changed files with 68 additions and 4 deletions
  1. 2
    1
      .gitignore
  2. 4
    0
      .testr.conf
  3. 9
    0
      .zuul.yaml
  4. 0
    0
      gerritbot/tests/__init__.py
  5. 0
    0
      gerritbot/tests/unit/__init__.py
  6. 35
    0
      gerritbot/tests/unit/test_bot.py
  7. 3
    0
      test-requirements.txt
  8. 15
    3
      tox.ini

+ 2
- 1
.gitignore View File

@@ -7,4 +7,5 @@ dist/*
7 7
 build/*
8 8
 *.pyc
9 9
 doc/build/*
10
-doc/source/api/*
10
+doc/source/api/*
11
+.stestr/

+ 4
- 0
.testr.conf View File

@@ -0,0 +1,4 @@
1
+[DEFAULT]
2
+test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} OS_TEST_TIMEOUT=60 ${PYTHON:-python} -m subunit.run discover -t ./ ${TESTS_DIR:-./gerritbot/tests/unit/} $LISTOPT $IDOPTION
3
+test_id_option=--load-list $IDFILE
4
+test_list_option=--list

+ 9
- 0
.zuul.yaml View File

@@ -0,0 +1,9 @@
1
+- project:
2
+    check:
3
+      jobs:
4
+        - tox-pep8
5
+        - tox-py27
6
+    gate:
7
+      jobs:
8
+        - tox-pep8
9
+        - tox-py27

+ 0
- 0
gerritbot/tests/__init__.py View File


+ 0
- 0
gerritbot/tests/unit/__init__.py View File


+ 35
- 0
gerritbot/tests/unit/test_bot.py View File

@@ -0,0 +1,35 @@
1
+#
2
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
3
+#    not use this file except in compliance with the License. You may obtain
4
+#    a copy of the License at
5
+#
6
+#         http://www.apache.org/licenses/LICENSE-2.0
7
+#
8
+#    Unless required by applicable law or agreed to in writing, software
9
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11
+#    License for the specific language governing permissions and limitations
12
+#    under the License.
13
+
14
+import testtools
15
+import yaml
16
+
17
+import gerritbot.bot as bot
18
+
19
+CHANNEL_CONFIG_YAML = """
20
+openstack-dev:
21
+    events:
22
+      - patchset-created
23
+      - change-merged
24
+    projects:
25
+      - openstack/nova
26
+      - openstack/swift
27
+    branches:
28
+      - master
29
+"""
30
+
31
+
32
+class ChannelConfigTestCase(testtools.TestCase):
33
+    def test_missing_octothorpe(self):
34
+        channel_config = bot.ChannelConfig(yaml.load(CHANNEL_CONFIG_YAML))
35
+        self.assertEqual(['#openstack-dev'], channel_config.channels)

+ 3
- 0
test-requirements.txt View File

@@ -1,2 +1,5 @@
1 1
 hacking>=0.10.0,<0.11
2 2
 sphinx>=1.1.2
3
+os-testr>=0.8.0 # Apache-2.0
4
+mock>=2.0.0 # BSD
5
+testtools>=1.4.0 # MIT

+ 15
- 3
tox.ini View File

@@ -1,9 +1,21 @@
1 1
 [tox]
2
-envlist = pep8
2
+envlist = py27,pep8
3 3
 
4 4
 [testenv]
5
-deps = -r{toxinidir}/requirements.txt
6
-       -r{toxinidir}/test-requirements.txt
5
+usedevelop = True
6
+install_command = pip install {opts} {packages}
7
+setenv = VIRTUAL_ENV={envdir}
8
+         PYTHONDONTWRITEBYTECODE = 1
9
+         LANGUAGE=en_US
10
+         LC_ALL=en_US.UTF-8
11
+         PYTHONWARNINGS=default::DeprecationWarning
12
+         TESTS_DIR=./gerritbot/tests/unit/
13
+deps = -r{toxinidir}/test-requirements.txt
14
+whitelist_externals = rm
15
+commands =
16
+    rm -f .testrepository/times.dbm
17
+    ostestr {posargs}
18
+passenv = http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY
7 19
 
8 20
 
9 21
 [testenv:pep8]

Loading…
Cancel
Save