Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement __eq__ method for Cell #1063

Merged
merged 8 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions gspread/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ def __repr__(self):
repr(self.value),
)

def __eq__(self, other):
return (
self.row == other.row
and self.col == other.col
and self.value == other.value
)

@property
def row(self):
"""Row number of the cell.
Expand Down
15 changes: 15 additions & 0 deletions tests/cell_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ def test_properties(self):
self.assertEqual(cell.row, 1)
self.assertEqual(cell.col, 1)

@pytest.mark.vcr()
def test_equality(self):
sg = self._sequence_generator()
update_value = next(sg)
self.sheet.update_acell("A1", update_value)
cell = self.sheet.acell("A1")
same_cell = self.sheet.cell(1, 1)
self.assertEqual(cell, same_cell)
self.sheet.update_acell("A2", update_value)
another_cell = self.sheet.acell("A2")
self.assertNotEqual(cell, another_cell)
self.sheet.update_acell("B1", update_value)
another_cell = self.sheet.acell("B1")
self.assertNotEqual(cell, another_cell)

@pytest.mark.vcr()
def test_numeric_value(self):
numeric_value = 1.0 / 1024
Expand Down