From 7588c1ca2be7befd5145510fdff707e4d443775c Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Mon, 21 Nov 2016 19:41:22 -0500 Subject: [PATCH] Rename .one to .first --- records.py | 2 +- tests/test_records.py | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/records.py b/records.py index 5afc071..afa0721 100644 --- a/records.py +++ b/records.py @@ -200,7 +200,7 @@ class RecordCollection(object): def as_dict(self, ordered=False): return self.all(as_dict=not(ordered), as_ordereddict=ordered) - def one(self, default=None, as_dict=False, as_ordereddict=False): + def first(self, default=None, as_dict=False, as_ordereddict=False): """Returns a single record for the RecordCollection, or `default`.""" # Try to get a record, or return default. diff --git a/tests/test_records.py b/tests/test_records.py index f45b141..b5d124f 100644 --- a/tests/test_records.py +++ b/tests/test_records.py @@ -58,33 +58,33 @@ class TestRecordCollection: assert rows.all() == [IdRecord(0), IdRecord(1), IdRecord(2)] - # one + # first - def test_one_returns_a_single_record(self): + def test_first_returns_a_single_record(self): rows = records.RecordCollection(IdRecord(i) for i in range(1)) - assert rows.one() == IdRecord(0) + assert rows.first() == IdRecord(0) - def test_one_defaults_to_None(self): + def test_first_defaults_to_Nfirst(self): rows = records.RecordCollection(iter([])) - assert rows.one() is None + assert rows.first() is None - def test_one_default_is_overridable(self): + def test_first_default_is_overridable(self): rows = records.RecordCollection(iter([])) - assert rows.one('Cheese') == 'Cheese' + assert rows.first('Cheese') == 'Cheese' - def test_one_raises_when_more_than_one(self): + def test_first_raises_when_more_than_first(self): rows = records.RecordCollection(IdRecord(i) for i in range(3)) - raises(ValueError, rows.one) + raises(ValueError, rows.first) - def test_one_raises_default_if_its_an_exception_subclass(self): + def test_first_raises_default_if_its_an_exception_subclass(self): rows = records.RecordCollection(iter([])) class Cheese(Exception): pass - raises(Cheese, rows.one, Cheese) + raises(Cheese, rows.first, Cheese) - def test_one_raises_default_if_its_an_exception_instance(self): + def test_first_raises_default_if_its_an_exception_instance(self): rows = records.RecordCollection(iter([])) class Cheese(Exception): pass - raises(Cheese, rows.one, Cheese('cheddar')) + raises(Cheese, rows.first, Cheese('cheddar')) class TestRecord: