def test_big_safe_expr(self):
     code = "(['26 One'] if k_eight is not None and 'Blah' in k_eight else []) " +\
         "+ (['26 Two'] if k_eight is not None and 'Blah-Blah' in k_eight " +\
         "else []) + (['26 Three'] if k_eight is not None and " +\
         "'Blah-Blah-Blah' in k_eight else [])".strip()
     checker = PythonExpressionChecker(code)
     checker.test_expression()
     self.assertEqual(0, len(checker.errors))
     self.assertEqual(0, len(checker.warnings))
    def test_warn_is_str(self):
        code = "temperature is '10'"
        checker = PythonExpressionChecker(code)
        checker.test_expression()
        self.assertEqual(1, len(checker.warnings))

        code = "temperature == '10'"
        checker = PythonExpressionChecker(code)
        checker.test_expression()
        self.assertEqual(0, len(checker.warnings))
    def test_warn_is_binop(self):
        code = "temperature is 5 - 2"
        checker = PythonExpressionChecker(code)
        checker.test_expression()
        self.assertEqual(1, len(checker.warnings))
        self.assertTrue("temperature is 5 - 2" in checker.warnings[0])

        code = "temperature is 5 / 2"
        checker = PythonExpressionChecker(code)
        checker.test_expression()
        self.assertTrue("temperature is 5 / 2" in checker.warnings[0])
    def test_warn_is_diff_types(self):
        code = "temperature is True"
        checker = PythonExpressionChecker(code)
        checker.test_expression()
        self.assertEqual(1, len(checker.warnings))
        self.assertTrue("temperature is True" in checker.warnings[0])

        code = "temperature is 10.2"
        checker = PythonExpressionChecker(code)
        checker.test_expression()
        self.assertEqual(1, len(checker.warnings))
        self.assertTrue("temperature is 10.2" in checker.warnings[0])
 def test_avg_len_with_warns(self):
     code = "k_nine if k_nine is '' else float(k_19) / 234.6 if k_19 else None"
     checker = PythonExpressionChecker(code)
     checker.test_expression()
     self.assertEqual(0, len(checker.errors))
     self.assertEqual(1, len(checker.warnings))
 def test_ternary(self):
     code = "1 if k_nine is '' else 0"
     checker = PythonExpressionChecker(code)
     checker.test_expression()
     self.assertEqual(0, len(checker.errors))
     self.assertEqual(1, len(checker.warnings))
 def test_complex(self):
     code = 'k_one - k_14 if k_one is \'1\' and k_14 else None'
     checker = PythonExpressionChecker(code)
     checker.test_expression()
     self.assertEqual(0, len(checker.errors))
     self.assertEqual(1, len(checker.warnings))
 def test_warn_is_expr(self):
     code = "temperature is (5 - 2) * 2"
     checker = PythonExpressionChecker(code)
     checker.test_expression()
     self.assertEqual(1, len(checker.errors))
     self.assertTrue("temperature is (5 - 2) * 2" in checker.errors[0])