Beispiel #1
0
    def test_parse_one(self):
        with self.assertRaises(AssertionError):
            parser.parse_one("""
              2014-12-15 * 2014-12-15
            """)

        entry = parser.parse_one("""
          2014-12-15 * "Payee" "Narration"
            Assets:Checking   101.23 USD
            Equity:Blah
        """)
        self.assertTrue(isinstance(entry, data.Transaction))
Beispiel #2
0
    def test_match_1(self):
        entry = parser.parse_one("""
2020-04-08 ! "AMZN Mktp US*L08746BB3"
  match-key: "2020040824692160098100992944500"
  ofx-type: "DEBIT"
  * Liabilities:CreditCard:Chase:Amazon  -39.98 USD
  ! Expenses:FIXME                        39.98 USD
""")
        assert entry.flag == "!"
        ruler = Rule({
            'match-narration': "AMZN Mktp *.",
            'set-account': 'Expenses:Shopping'
        })
        result = ruler.check(entry)
        self.assertIsNotNone(result)
        new_entry = ruler.modify_entry(entry, result)
        self.assertEqual(new_entry.flag, '*')
    def test_test_expect_extract(self, extract_mock):
        importer = _DummyImporter()

        string = textwrap.dedent("""
          2013-01-28 * "Something"
            Assets:Bank:Checking  656.00 USD
            Expenses:BobaLife
        """)
        entry = parser.parse_one(string)

        filename = path.join(self.tempdir, 'input.csv')
        expect_filename = path.join(self.tempdir, 'input.csv.extract')
        with open(filename, 'w'):
            pass
        with open(expect_filename, 'w') as file:
            file.write(string)

        # Required to trigger the test creation.
        with mock.patch.object(importer.__class__, 'extract') as imp_meth:
            imp_meth.__func__ = True
            imp_meth.return_value = []

            # Test actual working import.
            extract_mock.return_value = [entry]
            for method, *args in regression.compare_sample_files(
                    importer, self.tempdir):
                try:
                    method(*args)
                except Exception as exc:
                    self.fail("Unexpected exception: {}".format(exc))
            extract_mock.assert_called_once_with(filename, importer, None,
                                                 None)

            # Check a missing file.
            extract_mock.reset_mock()
            os.remove(expect_filename)
            for method, *args in regression.compare_sample_files(
                    importer, self.tempdir):
                with self.assertRaises(unittest.case.SkipTest):
                    method(*args)
            self.assertEqual(1, extract_mock.call_count)
	except:
		pass

if instance == None:
	print("No suitable importer!")
	exit(1)

new_entries = instance.parse()


with open(args.out, 'w') as f:
	printer.print_entries(new_entries, file = f)

print('Outputed to ' + args.out)
exit(0)

file = parser.parse_one('''
2018/01/15 * "测试" "测试"
	Assets:Test 300 CNY
	Income:Test

''')
print(file.postings)


file.postings[0] = file.postings[0]._replace(units = file.postings[0].units._replace(number = 100))
print(file.postings[0])

data = printer.format_entry(file)
print(data)