def test_no_hasattr_everything_is_fine(self): file_path = self._given_a_file_in_test_dir( 'import os' ) checker = PloneHasattrChecker(None, file_path) ret = list(checker.run()) self.assertEqual(len(ret), 0)
def test_hasattr(self): file_path = self._given_a_file_in_test_dir('a = 3\n' '\n' ' hasattr(a, "max")\n') checker = PloneHasattrChecker(None, file_path) ret = list(checker.run()) self.assertEqual(len(ret), 1) self.assertEqual(ret[0][0], 3) self.assertEqual(ret[0][1], 4) self.assertTrue(ret[0][2].startswith('P002 found '))
def test_hasattr(self): file_path = self._given_a_file_in_test_dir( 'a = 3\n' '\n' ' hasattr(a, "max")\n' ) checker = PloneHasattrChecker(None, file_path) ret = list(checker.run()) self.assertEqual(len(ret), 1) self.assertEqual(ret[0][0], 3) self.assertEqual(ret[0][1], 4) self.assertTrue(ret[0][2].startswith('P002 found '))
def test_stdin(self, stdin_get_value): stdin_value = mock.Mock() stdin_value.splitlines.return_value = [ 'a = 3\n', '\n', ' hasattr(a, "max")\n', ] stdin_get_value.return_value = stdin_value checker = PloneHasattrChecker(None, 'stdin') ret = list(checker.run()) self.assertEqual(len(ret), 1) self.assertEqual(ret[0][0], 3) self.assertEqual(ret[0][1], 4) self.assertTrue(ret[0][2].startswith('P002 found '))
def test_no_hasattr_everything_is_fine(self): file_path = self._given_a_file_in_test_dir('import os') checker = PloneHasattrChecker(None, file_path) ret = list(checker.run()) self.assertEqual(len(ret), 0)