Best Python code snippet using assertpy_python
test_grid.py
Source:test_grid.py
...7 [5, 6, 7, 8],8 [9, 10, 11, 12]])9 def test_rows(self):10 rows = self.DEFAULT_GRID.rows()11 assert_that(rows).described_as('Rows is immutable').is_not_same_as(self.DEFAULT_GRID.grid)12 assert_that(rows).is_equal_to([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])13 def test_row_first(self):14 first_row = self.DEFAULT_GRID.row(0)15 assert_that(first_row).described_as('Row is immutable').is_not_same_as(self.DEFAULT_GRID.grid[0])16 assert_that(first_row).is_equal_to([1, 2, 3, 4])17 def test_row_second(self):18 second_row = self.DEFAULT_GRID.row(1)19 assert_that(second_row).described_as('Row is immutable').is_not_same_as(self.DEFAULT_GRID.grid[1])20 assert_that(second_row).is_equal_to([5, 6, 7, 8])21 def test_columns(self):22 columns = self.DEFAULT_GRID.columns()23 assert_that(columns).is_equal_to([[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]])24 def test_column_first(self):25 first_column = self.DEFAULT_GRID.column(0)26 assert_that(first_column).is_equal_to([1, 5, 9])27 def test_column_second(self):28 second_column = self.DEFAULT_GRID.column(1)29 assert_that(second_column).is_equal_to([2, 6, 10])30 def test_rotate_right(self):31 rotated = self.DEFAULT_GRID.rotate_right()32 assert_that(rotated).is_instance_of(Grid)33 assert_that(rotated).described_as('Rotate is immutable').is_not_same_as(self.DEFAULT_GRID)34 assert_that(rotated.grid).is_equal_to([[9, 5, 1], [10, 6, 2], [11, 7, 3], [12, 8, 4]])35 def test_rotate_left(self):36 rotated = self.DEFAULT_GRID.rotate_left()37 assert_that(rotated).is_instance_of(Grid)38 assert_that(rotated).described_as('Rotate is immutable').is_not_same_as(self.DEFAULT_GRID)39 assert_that(rotated.grid).is_equal_to([[4, 8, 12], [3, 7, 11], [2, 6, 10], [1, 5, 9]])40 def test_flip_horizontally(self):41 flipped = self.DEFAULT_GRID.flip_horizontally()42 assert_that(flipped).is_instance_of(Grid)43 assert_that(flipped).described_as('Flip is immutable').is_not_same_as(self.DEFAULT_GRID)44 assert_that(flipped.grid).is_equal_to([[9, 10, 11, 12], [5, 6, 7, 8], [1, 2, 3, 4]])45 def test_flip_vertically(self):46 flipped = self.DEFAULT_GRID.flip_vertically()47 assert_that(flipped).is_instance_of(Grid)48 assert_that(flipped).described_as('Flip is immutable').is_not_same_as(self.DEFAULT_GRID)49 assert_that(flipped.grid).is_equal_to([[4, 3, 2, 1], [8, 7, 6, 5], [12, 11, 10, 9]])50 def test_visualize(self):51 out = StringIO()52 self.DEFAULT_GRID.visualize(out=out)53 assert_that(out.getvalue()).is_equal_to(54 f'----- width: 4, height: 3 -----\n 1 2 3 4\n 5 6 7 8\n 9 10 11 12\n')55 def test_equals(self):56 copied_grid = Grid(self.DEFAULT_GRID.grid.copy())57 assert_that(copied_grid).is_equal_to(self.DEFAULT_GRID)58class DirectionTest(unittest.TestCase):59 def test_opposite(self):60 assert_that(Direction.NORTH.opposite()).is_equal_to(Direction.SOUTH)61 assert_that(Direction.EAST.opposite()).is_equal_to(Direction.WEST)62 assert_that(Direction.SOUTH.opposite()).is_equal_to(Direction.NORTH)63 assert_that(Direction.WEST.opposite()).is_equal_to(Direction.EAST)64class PositionTest(unittest.TestCase):65 def test_add_north(self):66 init = Position(0, 0)67 new = init.add(Direction.NORTH)68 assert_that(new).is_not_same_as(init)69 assert_that(new.x).is_equal_to(0)70 assert_that(new.y).is_equal_to(1)71 def test_add_east(self):72 init = Position(0, 0)73 new = init.add(Direction.EAST)74 assert_that(new).is_not_same_as(init)75 assert_that(new.x).is_equal_to(1)76 assert_that(new.y).is_equal_to(0)77 def test_add_south(self):78 init = Position(0, 0)79 new = init.add(Direction.SOUTH)80 assert_that(new).is_not_same_as(init)81 assert_that(new.x).is_equal_to(0)82 assert_that(new.y).is_equal_to(-1)83 def test_add_west(self):84 init = Position(0, 0)85 new = init.add(Direction.WEST)86 assert_that(new).is_not_same_as(init)87 assert_that(new.x).is_equal_to(-1)...
test_same_as.py
Source:test_same_as.py
...36 assert_that(obj).is_same_as(other)37 fail('should have raised error')38 except AssertionError as ex:39 assert_that(str(ex)).matches('Expected <.+> to be identical to <.+>, but was not.')40def test_is_not_same_as():41 obj = object()42 other = object()43 assert_that(obj).is_not_same_as(other)44 assert_that(obj).is_not_same_as(1)45 assert_that(obj).is_not_same_as(True)46 assert_that(1).is_not_same_as(2)47 assert_that({'a':1}).is_not_same_as({'a':1})48 assert_that([1,2,3]).is_not_same_as([1,2,3])49 assert_that((1,2,3)).is_not_same_as((1,2,3))50def test_is_not_same_as_failure():51 for obj in [object(), 1, 'foo', True, None, 123.456]:52 try:53 assert_that(obj).is_not_same_as(obj)54 fail('should have raised error')55 except AssertionError as ex:...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!