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

16 statements  

« prev     ^ index     » next       coverage.py v7.3.0, created at 2024-12-21 12:23 +0000

1import unittest 

2 

3from src import xml 

4 

5 

6class TestCase(unittest.TestCase): 

7 def test_prettify_xml(self): 

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

9 expected = ''' 

10<some> 

11 <xml /> 

12</some> 

13 '''.strip() 

14 self.assertEqual(actual, expected) 

15 actual = xml.prettify(''' 

16<!doctype html> 

17<h1>Hello</h1> 

18 '''.strip()) 

19 expected = ''' 

20<!doctype html> 

21<h1>Hello</h1> 

22 '''.strip() 

23 self.assertEqual(actual, expected) 

24 

25 original = ''' 

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

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

28 <title>Hey Reader!</title> 

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

30 <author> 

31 <name>Alex Recker</name> 

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

33 </author> 

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

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

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

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

38 <entry> 

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

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

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

42 <author> 

43 <name>Alex Recker</name> 

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

45 </author> 

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

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

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

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

50 </entry> 

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

52 actual = xml.prettify(original) 

53 self.assertEqual(actual, original) 

54 

55 with self.assertRaisesRegex(ValueError, 'Hello'): 

56 xml.prettify(''' 

57<!doctype html> 

58<h1>Hello 

59 '''.strip()) 

60 self.assertEqual(actual, expected)