def testMultilineStatement(self):
    formula = """
s.initialize()
s.go()
"""
    fs = FormulaStatement(formula, "TEST_FORMULA")
    self.assertIsNone(fs.do())
    self.assertEqual(fs.getStatement().count("="), 0)
    self.assertFalse(fs.isExpression())
    def testMultilineStatement(self):
        formula = """
s.initialize()
s.go()
"""
        fs = FormulaStatement(formula, "TEST_FORMULA")
        self.assertIsNone(fs.do())
        self.assertEqual(fs.getStatement().count("="), 0)
        self.assertFalse(fs.isExpression())
 def testIsEquivalent(self):
     formula_statement = FormulaStatement(VALID_FORMULA, COLUMN_NAME)
     self.assertTrue(self.fs.isEquivalent(formula_statement))
     self.assertFalse(self.fs.isEquivalent(self.invalid_fs))
 def testSemicolonOneStatement(self):
     formula = "s.initialize();"
     fs = FormulaStatement(formula, "TEST_FORMULA")
     self.assertIsNone(fs.do())
     self.assertEqual(fs.getStatement().count("="), 0)
     self.assertFalse(fs.isExpression())
 def testAmbiguousStatement(self):
     formula = "s.initialize()"
     fs = FormulaStatement(formula, "TEST_FORMULA")
     self.assertIsNone(fs.do())
     self.assertEqual(fs.getStatement().count("="), 1)
     self.assertTrue(fs.isExpression())
 def testStatement(self):
     formula = "%s = %s" % ("TEST_FORMULA", VALID_FORMULA)
     fs = FormulaStatement(formula, "TEST_FORMULA")
     self.assertIsNone(fs.do())
     self.assertEqual(fs.getStatement().count("="), 1)
     self.assertFalse(fs.isExpression())
 def testExpression(self):
     fs = FormulaStatement(VALID_FORMULA, "TEST_FORMULA")
     self.assertIsNone(fs.do())
     self.assertEqual(fs.getStatement().count("="), 1)
     self.assertTrue(fs.isExpression())
 def setUp(self):
     self.fs = FormulaStatement(VALID_FORMULA, COLUMN_NAME)
     self.invalid_fs = FormulaStatement(INVALID_FORMULA, "INVALID")
class TestFormulaStatement(unittest.TestCase):
    def setUp(self):
        self.fs = FormulaStatement(VALID_FORMULA, COLUMN_NAME)
        self.invalid_fs = FormulaStatement(INVALID_FORMULA, "INVALID")

    def testDo(self):
        error = self.fs.do()
        self.assertIsNone(error)
        error = self.invalid_fs.do()
        self.assertIsNotNone(error)

    def testGetStatement(self):
        self.fs.do()
        statement = self.fs.getStatement()
        expected_statement = "%s = %s" % (COLUMN_NAME, VALID_FORMULA)
        self.assertEqual(statement, expected_statement)

    def testGetFormula(self):
        self.assertEqual(VALID_FORMULA, self.fs.getFormula())

    def testExpression(self):
        fs = FormulaStatement(VALID_FORMULA, "TEST_FORMULA")
        self.assertIsNone(fs.do())
        self.assertEqual(fs.getStatement().count("="), 1)
        self.assertTrue(fs.isExpression())

    def testStatement(self):
        formula = "%s = %s" % ("TEST_FORMULA", VALID_FORMULA)
        fs = FormulaStatement(formula, "TEST_FORMULA")
        self.assertIsNone(fs.do())
        self.assertEqual(fs.getStatement().count("="), 1)
        self.assertFalse(fs.isExpression())

    def testAmbiguousStatement(self):
        formula = "s.initialize()"
        fs = FormulaStatement(formula, "TEST_FORMULA")
        self.assertIsNone(fs.do())
        self.assertEqual(fs.getStatement().count("="), 1)
        self.assertTrue(fs.isExpression())

    def testMultilineStatement(self):
        formula = """
s.initialize()
s.go()
"""
        fs = FormulaStatement(formula, "TEST_FORMULA")
        self.assertIsNone(fs.do())
        self.assertEqual(fs.getStatement().count("="), 0)
        self.assertFalse(fs.isExpression())

    def testSemicolonStatement(self):
        formula = "s.initialize();s.go()"
        fs = FormulaStatement(formula, "TEST_FORMULA")
        self.assertIsNone(fs.do())
        self.assertEqual(fs.getStatement().count("="), 0)
        self.assertFalse(fs.isExpression())

    def testSemicolonOneStatement(self):
        formula = "s.initialize();"
        fs = FormulaStatement(formula, "TEST_FORMULA")
        self.assertIsNone(fs.do())
        self.assertEqual(fs.getStatement().count("="), 0)
        self.assertFalse(fs.isExpression())

    def testIsEquivalent(self):
        formula_statement = FormulaStatement(VALID_FORMULA, COLUMN_NAME)
        self.assertTrue(self.fs.isEquivalent(formula_statement))
        self.assertFalse(self.fs.isEquivalent(self.invalid_fs))
 def testSemicolonOneStatement(self):
   formula = "s.initialize();"
   fs = FormulaStatement(formula, "TEST_FORMULA")
   self.assertIsNone(fs.do())
   self.assertEqual(fs.getStatement().count("="), 0)
   self.assertFalse(fs.isExpression())
 def testAmbiguousStatement(self):
   formula = "s.initialize()"
   fs = FormulaStatement(formula, "TEST_FORMULA")
   self.assertIsNone(fs.do())
   self.assertEqual(fs.getStatement().count("="), 1)
   self.assertTrue(fs.isExpression())
 def testStatement(self):
   formula = "%s = %s" % ("TEST_FORMULA", VALID_FORMULA)
   fs = FormulaStatement(formula, "TEST_FORMULA")
   self.assertIsNone(fs.do())
   self.assertEqual(fs.getStatement().count("="), 1)
   self.assertFalse(fs.isExpression())
 def testExpression(self):
   fs = FormulaStatement(VALID_FORMULA, "TEST_FORMULA")
   self.assertIsNone(fs.do())
   self.assertEqual(fs.getStatement().count("="), 1)
   self.assertTrue(fs.isExpression())
 def setUp(self):
   self.fs = FormulaStatement(VALID_FORMULA, COLUMN_NAME)
   self.invalid_fs = FormulaStatement(INVALID_FORMULA, "INVALID")
class TestFormulaStatement(unittest.TestCase):
  
  def setUp(self):
    self.fs = FormulaStatement(VALID_FORMULA, COLUMN_NAME)
    self.invalid_fs = FormulaStatement(INVALID_FORMULA, "INVALID")

  def testDo(self):
    error = self.fs.do()
    self.assertIsNone(error)
    error = self.invalid_fs.do()
    self.assertIsNotNone(error)

  def testGetStatement(self):
    self.fs.do()
    statement = self.fs.getStatement()
    expected_statement = "%s = %s" % (COLUMN_NAME, VALID_FORMULA)
    self.assertEqual(statement, expected_statement)

  def testGetFormula(self):
    self.assertEqual(VALID_FORMULA, self.fs.getFormula())

  def testExpression(self):
    fs = FormulaStatement(VALID_FORMULA, "TEST_FORMULA")
    self.assertIsNone(fs.do())
    self.assertEqual(fs.getStatement().count("="), 1)
    self.assertTrue(fs.isExpression())

  def testStatement(self):
    formula = "%s = %s" % ("TEST_FORMULA", VALID_FORMULA)
    fs = FormulaStatement(formula, "TEST_FORMULA")
    self.assertIsNone(fs.do())
    self.assertEqual(fs.getStatement().count("="), 1)
    self.assertFalse(fs.isExpression())

  def testAmbiguousStatement(self):
    formula = "s.initialize()"
    fs = FormulaStatement(formula, "TEST_FORMULA")
    self.assertIsNone(fs.do())
    self.assertEqual(fs.getStatement().count("="), 1)
    self.assertTrue(fs.isExpression())

  def testMultilineStatement(self):
    formula = """
s.initialize()
s.go()
"""
    fs = FormulaStatement(formula, "TEST_FORMULA")
    self.assertIsNone(fs.do())
    self.assertEqual(fs.getStatement().count("="), 0)
    self.assertFalse(fs.isExpression())

  def testSemicolonStatement(self):
    formula = "s.initialize();s.go()"
    fs = FormulaStatement(formula, "TEST_FORMULA")
    self.assertIsNone(fs.do())
    self.assertEqual(fs.getStatement().count("="), 0)
    self.assertFalse(fs.isExpression())

  def testSemicolonOneStatement(self):
    formula = "s.initialize();"
    fs = FormulaStatement(formula, "TEST_FORMULA")
    self.assertIsNone(fs.do())
    self.assertEqual(fs.getStatement().count("="), 0)
    self.assertFalse(fs.isExpression())

  def testIsEquivalent(self):
    formula_statement = FormulaStatement(VALID_FORMULA, COLUMN_NAME)
    self.assertTrue(self.fs.isEquivalent(formula_statement))
    self.assertFalse(self.fs.isEquivalent(self.invalid_fs))