Coverage for src/test/test_xml.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.3.0, created at 2024-02-23 06:18 -0600

1# flake8: noqa 

2 

3import unittest 

4 

5from src import xml 

6 

7 

8class TestCase(unittest.TestCase): 

9 def test_prettify_xml(self): 

10 actual = xml.prettify('<some><xml></xml></some>') 

11 expected = ''' 

12<some> 

13 <xml /> 

14</some> 

15 '''.strip() 

16 self.assertEqual(actual, expected) 

17 actual = xml.prettify(''' 

18<!doctype html> 

19<h1>Hello</h1> 

20 '''.strip()) 

21 expected = ''' 

22<!doctype html> 

23<h1>Hello</h1> 

24 '''.strip() 

25 self.assertEqual(actual, expected) 

26 

27 original = ''' 

28<?xml version="1.0" encoding="utf-8"?> 

29<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/"> 

30 <title>Hey Reader!</title> 

31 <subtitle>personal online journal of Alex Recker</subtitle> 

32 <author> 

33 <name>Alex Recker</name> 

34 <email>alex@reckerfamily.com</email> 

35 </author> 

36 <updated>2023-09-05T00:00:00+00:00</updated> 

37 <id>https://www.alexrecker.com/feed.xml</id> 

38 <link href="https://www.alexrecker.com/feed.xml" rel="self" type="application/atom+xml" /> 

39 <link href="https://www.alexrecker.com" rel="alternate" type="text/html" /> 

40 <entry> 

41 <title>Tuesday, September 5 2023</title> 

42 <published>2023-09-05T00:00:00+00:00</published> 

43 <updated>2023-09-05T00:00:00+00:00</updated> 

44 <author> 

45 <name>Alex Recker</name> 

46 <email>alex@reckerfamily.com</email> 

47 </author> 

48 <id>https://www.alexrecker.com/2023-09-05.html</id> 

49 <link href="https://www.alexrecker.com/2023-09-05.html" /> 

50 <media:thumbnail url="https://www.alexrecker.com/images/banners/2023-09-05.jpg" /> 

51 <media:content medium="image" url="https://www.alexrecker.com/images/banners/2023-09-05.jpg" /> 

52 </entry> 

53</feed>'''.strip() 

54 actual = xml.prettify(original) 

55 self.assertEqual(actual, original)