Exemple #1
0
    def test_write_command__formula_reference_cyclic_dep(self):
        try:
            spreadsheet.write_command("a1 =~a2")
        except FormulaException:
            pass

        with self.assertRaises(FormulaException):
            spreadsheet.write_command("a2 =~a1")
Exemple #2
0
 def test_save_and_open(self):
     filename = "file.out"
     spreadsheet.write_command("a1 hi")
     spreadsheet.save_sheet(filename)
     spreadsheet.spreadsheet = {}
     self.assertTrue("A1" not in spreadsheet.spreadsheet)
     spreadsheet.open_sheet(filename)
     result = spreadsheet.read_command("a1")
     self.assertEqual(result, "hi")
     os.remove(filename)
Exemple #3
0
 def test_write_command__formula_func_lookup_lowercase(self):
     spreadsheet.write_command("a1 1")
     spreadsheet.write_command("a2 2")
     spreadsheet.write_command("b1 10")
     spreadsheet.write_command("b2 20")
     result = spreadsheet.write_command("c1 =LOOKUP(\"a1:B2\",1,1)")
     self.assertEqual(result, 10)
Exemple #4
0
 def test_write_command__formula_constant_text(self):
     result = spreadsheet.write_command("a1 =\"hi\"")
     self.assertEqual(result, "hi")
     self.assertEqual(type(result), str)
Exemple #5
0
 def test_write_command__formula_constant_number(self):
     result = spreadsheet.write_command("a1 =1")
     self.assertEqual(result, 1.0)
     self.assertEqual(type(result), float)
Exemple #6
0
 def test_write_command__success_text(self):
     result = spreadsheet.write_command("a1 hi")
     self.assertEqual(result, "hi")
     self.assertEqual(type(result), str)
Exemple #7
0
 def test_write_command__success_float(self):
     result = spreadsheet.write_command("a1 1.2")
     self.assertEqual(result, 1.2)
     self.assertEqual(type(result), float)
Exemple #8
0
 def test_write_command__success_lowercase(self):
     spreadsheet.write_command("a1 hi")
     self.assertTrue("A1" in spreadsheet.spreadsheet)
Exemple #9
0
 def test_write_command__formula_spaced(self):
     spreadsheet.write_command("h1 9")
     result = spreadsheet.write_command(
         "a1 = 2 * ( 3 + 5 ) + MIN( 3 , 2 ) * ~H1")
     self.assertEqual(result, 34)
Exemple #10
0
 def test_write_command__formula_multiply(self):
     result = spreadsheet.write_command("a1 =3*5")
     self.assertEqual(result, 15)
Exemple #11
0
 def test_write_command__formula_bracketed(self):
     result = spreadsheet.write_command("a1 =(3*5)")
     self.assertEqual(result, 15)
Exemple #12
0
 def test_write_command__formula_add(self):
     result = spreadsheet.write_command("a1 =1+2")
     self.assertEqual(result, 3)
Exemple #13
0
 def test_write_command__formula_func_mean(self):
     spreadsheet.write_command("a1 2")
     spreadsheet.write_command("a2 3")
     spreadsheet.write_command("a3 10")
     result = spreadsheet.write_command("a4 =MEAN(\"A1:A3\")")
     self.assertEqual(result, 5)
Exemple #14
0
 def test_write_command__formula_func_sum(self):
     spreadsheet.write_command("a1 1")
     spreadsheet.write_command("a2 2")
     spreadsheet.write_command("a3 10")
     result = spreadsheet.write_command("a4 =SUM(\"A1:A3\")")
     self.assertEqual(result, 13)
Exemple #15
0
 def test_write_command__formula_reference(self):
     spreadsheet.write_command("a1 =666")
     result = spreadsheet.write_command("a2 =~a1")
     self.assertEqual(result, 666)
Exemple #16
0
 def test_write_command__malformatted_args(self):
     with self.assertRaises(InputException):
         spreadsheet.write_command("a1")
Exemple #17
0
 def test_write_command__formula_reference_doesnt_exist(self):
     with self.assertRaises(FormulaException):
         spreadsheet.write_command("a2 =~a1")
Exemple #18
0
 def test_write_command__success_int(self):
     result = spreadsheet.write_command("a1 1")
     self.assertEqual(result, 1)
     self.assertEqual(type(result), int)
Exemple #19
0
 def test_write_command__formula_func_max(self):
     result = spreadsheet.write_command("a1 =MAX(1,2)")
     self.assertEqual(result, 2)
Exemple #20
0
 def test_write_command__formula_func_concat(self):
     result = spreadsheet.write_command("a1 =CONCAT(\"hi\",\"ho\")")
     self.assertEqual(result, "hiho")