Beispiel #1
0
def test_expense_save_raises_error_when_path_is_dir(tmpdir):
    path = os.path.join(tmpdir, 'test.csv')
    os.mkdir(path)

    ed = ExpenseCSVData(path)
    # This check if within with statement exception is raise.
    # Test fails if there is no exception of given type in a given block.
    with pytest.raises(UnableToOpenDataFileException):
        ed.save({'name': 'a', 'price': 1})
Beispiel #2
0
def test_expense_save():
    tmp_dir = tempfile.TemporaryDirectory()

    with tmp_dir as d:
        path = os.path.join(d, 'test.csv')
        ed = ExpenseCSVData(path)
        ed.save({'name': 'a', 'price': 1})

        with open(path, 'r') as f:
            l = f.readlines()

    assert len(l) == 2
Beispiel #3
0
 def add_product_cmd(self, new_product):
     writer = ExpenseCSVData('expense.csv')
     with writer:
         writer.save(new_product)
     data = get_expenses()
     self.listbox_variable.set(data)