New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial test #21

merged 6 commits into from Jun 7, 2018
Jump to file or symbol
Failed to load files and symbols.
+126 −1
Diff settings


Just for now

Viewing a subset of changes. View all

Adds write_xml() test

  • Loading branch information...
duskybomb committed May 28, 2018
commit 2f3ae4446cfb1b2603055e3956fb6936591d46c4
@@ -0,0 +1,53 @@
<rsm:CrossIndustryInvoice xmlns:qdt="urn:un:unece:uncefact:data:standard:QualifiedDataType:100" xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100" xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100" xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100" xmlns:xsi="">
<udt:DateTimeString format="102">20171031</udt:DateTimeString>
<ram:BuyerReference>CodeSERVICE A</ram:BuyerReference>
<ram:Name>FOURNISSEUR F</ram:Name>
<ram:ID schemeID="0002">99988877900017</ram:ID>
<ram:ID schemeID="VA">FR34999888779</ram:ID>
<ram:Name>CLIENT 1</ram:Name>
<ram:ID schemeID="0002">77788899100018</ram:ID>
<ram:TaxBasisTotalAmount currencyID="EUR">15976.87</ram:TaxBasisTotalAmount>
<ram:TaxTotalAmount currencyID="EUR">3195.37</ram:TaxTotalAmount>
<ram:GrandTotalAmount currencyID="EUR">19172.24</ram:GrandTotalAmount>
<ram:DuePayableAmount currencyID="EUR">19172.24</ram:DuePayableAmount>
@@ -1,6 +1,59 @@
import os
import unittest
from facturx.facturx import *
import xml.etree.ElementTree as ET
class XmlTree:

This comment has been minimized.


m3nu Jun 3, 2018

  • You can't plagiarize a whole code block without license and credit.
  • If a helper class is needed, it can't be in the test module.

m3nu Jun 3, 2018

  • You can't plagiarize a whole code block without license and credit.
  • If a helper class is needed, it can't be in the test module.
def __init__(self):
def convert_string_to_tree( xmlString):
return ET.fromstring(xmlString)
def xml_compare(self, x1, x2):
if x1.tag != x2.tag:
# print('Tags do not match: %s and %s' % (x1.tag, x2.tag))
return False
for name, value in x1.attrib.items():
if x2.attrib.get(name) != value:
# print('Attributes do not match: %s=%r, %s=%r'
# % (name, value, name, x2.attrib.get(name)))
return False
for name in x2.attrib.keys():
if name not in x1.attrib:
# print('x2 has an attribute x1 is missing: %s'
# % name)
return False
if not self.text_compare(x1.text, x2.text):
# print('text: %r != %r' % (x1.text, x2.text))
return False
if not self.text_compare(x1.tail, x2.tail):
# print('tail: %r != %r' % (x1.tail, x2.tail))
return False
cl1 = x1.getchildren()
cl2 = x2.getchildren()
if len(cl1) != len(cl2):
# print('children length differs, %i != %i'
# % (len(cl1), len(cl2)))
return False
i = 0
for c1, c2 in zip(cl1, cl2):
i += 1
if not self.xml_compare(c1, c2):
# print('children %i do not match: %s'
# % (i, c1.tag))
return False
return True
def text_compare(self, t1, t2):
if not t1 and not t2:
return True
if t1 == '*' or t2 == '*':
return True
return (t1 or '').strip() == (t2 or '').strip()
class TestReading(unittest.TestCase):
@@ -54,7 +107,26 @@ def test_write_pdf(self):
def test_write_xml(self):
compare_file_dir = os.path.join(os.path.dirname(__file__), 'compare')
expected_file_path = os.path.join(compare_file_dir, 'no_embedded_data.xml')
test_file_path = os.path.join(compare_file_dir, 'test.xml')
factx = FacturX(self.find_file('no_embedded_data.pdf'))
with open(expected_file_path, 'r') as expected_file, open(test_file_path, 'r') as test_file:
expected_file_tree = XmlTree.convert_string_to_tree(
test_file_tree = XmlTree.convert_string_to_tree(
comparator = XmlTree()
if comparator.xml_compare(expected_file_tree, test_file_tree):
self.assertTrue(False, "Files don't match")
def main():
ProTip! Use n and p to navigate between commits in a pull request.