Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1from e21_longest_word import find_longest_word, find_all_longest_words 

2import pytest 

3from io import StringIO 

4 

5 

6@pytest.fixture 

7def empty_file(tmp_path): 

8 f = tmp_path / 'emptyfile.txt' 

9 f.write_text('') 

10 return f 

11 

12 

13@pytest.fixture 

14def small_file(tmp_path): 

15 f = tmp_path / 'smallfile.txt' 

16 f.write_text('''This is the first line 

17and this is the second line''') 

18 return f 

19 

20 

21@pytest.fixture 

22def big_file(tmp_path): 

23 f = tmp_path / 'bigfile.txt' 

24 f.write_text('''This is the first line of a big file 

25 

26and this is the second line 

27and this is, to no one's surprise, the third line 

28but the biggest word will probably be encyclopedia''') 

29 return f 

30 

31 

32def test_small_file(small_file): 

33 assert find_longest_word(small_file) == 'second' 

34 

35 

36def test_big_file(big_file): 

37 assert find_longest_word(big_file) == 'encyclopedia' 

38 

39 

40def test_empty_directory(tmp_path): 

41 assert find_all_longest_words(tmp_path) == {} 

42 

43 

44def test_one_file(tmp_path, empty_file): 

45 assert find_all_longest_words(tmp_path) == {'emptyfile.txt': ''} 

46 

47 

48def test_all_files(tmp_path, empty_file, small_file, big_file): 

49 assert find_all_longest_words(tmp_path) == {'emptyfile.txt': '', 

50 'smallfile.txt': 'second', 

51 'bigfile.txt': 'encyclopedia'}