Skip to content

Commit

Permalink
Blacken the examples
Browse files Browse the repository at this point in the history
  • Loading branch information
offbyone committed Aug 29, 2020
1 parent fef76bf commit c13e4c4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
8 changes: 2 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ repos:
rev: 3.8.0a2
hooks:
- id: flake8
exclude: >-
(?x)^examples/.*\.py$
- repo: https://github.com/jazzband/pip-tools
rev: 5.1.1
hooks:
- id: pip-compile
files: ^requirements.*\.(in|txt)$

- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
Expand Down
27 changes: 17 additions & 10 deletions examples/CustomDateMatcher.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
sys.path.append('..')

sys.path.append("..")

from hamcrest.core.base_matcher import BaseMatcher
from hamcrest.core.helpers.hasmethod import hasmethod
Expand All @@ -17,16 +18,22 @@ def __init__(self, day):

def _matches(self, item):
"""Test whether item matches."""
if not hasmethod(item, 'weekday'):
if not hasmethod(item, "weekday"):
return False
return item.weekday() == self.day

def describe_to(self, description):
"""Describe the matcher."""
day_as_string = ['Monday', 'Tuesday', 'Wednesday', 'Thursday',
'Friday', 'Saturday', 'Sunday']
description.append_text('calendar date falling on ') \
.append_text(day_as_string[self.day])
day_as_string = [
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday",
]
description.append_text("calendar date falling on ").append_text(day_as_string[self.day])


def on_a_saturday():
Expand All @@ -37,19 +44,19 @@ def on_a_saturday():
class SampleTest(unittest.TestCase):
def testDateIsOnASaturday(self):
"""Example of successful match."""
d = datetime.date(2008, 04, 26)
d = datetime.date(2008, 4, 26)
assert_that(d, is_(on_a_saturday()))

def testFailsWithMismatchedDate(self):
"""Example of what happens with date that doesn't match."""
d = datetime.date(2008, 04, 06)
d = datetime.date(2008, 4, 6)
assert_that(d, is_(on_a_saturday()))

def testFailsWithNonDate(self):
"""Example of what happens with object that isn't a date."""
d = 'oops'
d = "oops"
assert_that(d, is_(on_a_saturday()))


if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()
15 changes: 8 additions & 7 deletions examples/ExampleWithAssertThat.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import sys
sys.path.append('..')

sys.path.append("..")

from hamcrest import *
import unittest


class ExampleWithAssertThat(unittest.TestCase):
def testUsingAssertThat(self):
assert_that('xx', is_('xx'))
assert_that('yy', is_not('xx'))
assert_that('i like cheese', contains_string('cheese'))
assert_that("xx", is_("xx"))
assert_that("yy", is_not("xx"))
assert_that("i like cheese", contains_string("cheese"))

def testCanAlsoSupplyDescriptiveReason(self):
assert_that('xx', is_('xx'), 'description')
assert_that("xx", is_("xx"), "description")

def testCanAlsoAssertPlainBooleans(self):
assert_that(True, 'This had better not fail')
assert_that(True, "This had better not fail")


if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()

0 comments on commit c13e4c4

Please sign in to comment.