Skip to content

Commit

Permalink
Wrote some unit tests and enabled Travis-CI. (GH-37)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariatta authored Oct 18, 2017
1 parent 2867c42 commit 8ac8fbd
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: python
cache: pip
python:
- 3.6
- 3.6-dev
- 3.7-dev
- nightly

install:
- python3 -m pip install -U -r dev-requirements.txt
script:
- python3 -m pytest tests/

4 changes: 4 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-r requirements.txt
pytest~=3.0.7
pytest-asyncio~=0.5.0
pytest-aiohttp~=0.1.3
Empty file added tests/__init__.py
Empty file.
48 changes: 48 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from unittest import mock


from backport import util


def test_title_normalization():
title = "abcd"
body = "1234"
assert util.normalize_title(title, body) == title

title = "[2.7] bpo-29243: Fix Makefile with respect to --enable-optimizations …"
body = "…(GH-1478)\r\n\r\nstuff"
expected = '[2.7] bpo-29243: Fix Makefile with respect to --enable-optimizations (GH-1478)'
assert util.normalize_title(title, body) == expected

title = "[2.7] bpo-29243: Fix Makefile with respect to --enable-optimizations …"
body = "…(GH-1478)"
assert util.normalize_title(title, body) == expected

title = "[2.7] bpo-29243: Fix Makefile with respect to --enable-optimizations (GH-14…"
body = "…78)"
assert util.normalize_title(title, body) == expected


def test_get_participants_different_creator_and_committer():
assert util.get_participants("miss-islington", "bedevere-bot") \
== "@miss-islington and @bedevere-bot"


def test_get_participants_same_creator_and_committer():
assert util.get_participants("miss-islington",
"miss-islington") == "@miss-islington"


@mock.patch('subprocess.check_output')
def test_is_cpython_repo_contains_first_cpython_commit(subprocess_check_output):
mock_output = b"""commit 7f777ed95a19224294949e1b4ce56bbffcb1fe9f
Author: Guido van Rossum <guido@python.org>
Date: Thu Aug 9 14:25:15 1990 +0000
Initial revision"""
subprocess_check_output.return_value = mock_output
assert util.is_cpython_repo()


def test_is_not_cpython_repo():
assert util.is_cpython_repo() == False

0 comments on commit 8ac8fbd

Please sign in to comment.