Coverage for tests/test_tyora.py: 100%

1 import pytest

2 from tyora import tyora

3

4

5 def test_parse_args_missing_args() -> None:

6 with pytest.raises(SystemExit):

7 tyora.parse_args()

8

9

10 def test_parse_args_command() -> None:

11 args = tyora.parse_args(["list"])

12 assert args.cmd == "list"

13

14

15 class TestFindLink:

16 valid_html = (

17 "<html><body>"

18 '<a href="somelink" class="someclass">sometext</a>'

19 "</body></html>"

20 )

21 invalid_html = "<html><body>No links here</body></html>"

22 valid_xpath = './/a[@class="someclass"]'

23 invalid_xpath = './/a[@class="somethingelse"]'

24 valid_return = {"href": "somelink", "text": "sometext"}

25

26 def test_find_link_success(self) -> None:

27 assert tyora.find_link(self.valid_html, self.valid_xpath) == self.valid_return

28

29 def test_find_link_bad_xpath(self) -> None:

30 assert tyora.find_link(self.valid_html, self.invalid_xpath) == {}

31

32 def test_find_link_bad_html(self) -> None:

33 assert tyora.find_link(self.invalid_html, self.valid_xpath) == {}

34

35

36 class TestParseForm:

37 valid_html = (

38 '<html><body><form action="someaction">'

39 '<input name="somename" value="somevalue">sometext</input>'

40 "</form></body></html>"

41 )

42 noform_html = "<html><body>No form here</body></html>"

43 noinput_html = (

44 '<html><body><form action="someaction">Nothing here</form></body></html>'

45 )

46

47

48# TODO: functions that use user input or read or write files

49 def test_create_config() -> None: ...

50

51

52 def test_write_config() -> None: ...

53

54

55 def test_read_config() -> None: ...

56

57

58 def test_get_cookiejar() -> None: ...