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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

 

import subprocess 

import unittest 

from pathlib import Path 

 

# PyLucid 

import pylucid 

from pylucid.pylucid_admin import Requirements 

from pylucid.pylucid_boot import VerboseSubprocess 

 

PACKAGE_PATH = Path(pylucid.__file__).parent 

 

 

class TestPyLucidAdmin(unittest.TestCase): 

""" 

Tests for pylucid/pylucid_admin.py 

""" 

def pylucid_admin_run(self, *args): 

args = ("pylucid_admin", ) + args 

try: 

return VerboseSubprocess(*args).verbose_output(check=False) 

except subprocess.CalledProcessError as err: 

self.fail("Subprocess error: %s" % err) 

 

def test_help(self): 

output = self.pylucid_admin_run("help") 

print(output) 

 

self.assertIn("pylucid_admin.py shell", output) 

self.assertIn("Available commands (type help <topic>):", output) 

 

self.assertIn("create_page_instance", output) 

self.assertIn("Create a PyLucid page instance.", output) 

 

self.assertIn("update_env", output) 

self.assertIn("Update all packages in virtualenv.", output) 

 

# If DocString is missing in do_<name>(): 

self.assertNotIn("Undocumented", output) 

 

def test_unknown_command(self): 

output = self.pylucid_admin_run("foo bar is unknown ;)") 

print(output) 

 

self.assertIn("pylucid_admin.py shell", output) 

self.assertIn("*** Unknown command: 'foo bar is unknown ;)' ***", output) 

 

def test_requirement_path(self): 

requirements = Requirements(package_path=PACKAGE_PATH) 

self.assertTrue(requirements.get_requirement_path().is_dir()) 

self.assertTrue(requirements.get_requirement_file_path().is_file()) 

 

@unittest.skipIf(Requirements(package_path=PACKAGE_PATH).normal_mode, "Only available in 'developer' mode.") 

def test_change_editable_address(self): 

""" 

All test runs on Travis-CI install PyLucid as editable! 

See .travis.yml 

""" 

requirements = Requirements(package_path=PACKAGE_PATH) 

 

self.assertFalse(requirements.normal_mode) 

 

pylucid_src_path = Path(requirements.src_path, "pylucid") 

print("pylucid_src_path: %r" % pylucid_src_path) 

 

self.assertTrue(pylucid_src_path.is_dir()) 

self.assertTrue(str(pylucid_src_path).endswith("/src/pylucid")) 

 

git_path = Path(pylucid_src_path, ".git") 

print("git_path: %r" % git_path) 

 

self.assertTrue(git_path.is_dir()) 

 

# Needed while developing with github write access url ;) 

output = VerboseSubprocess( 

"git", "remote", "set-url", "origin", "https://github.com/jedie/PyLucid.git", 

cwd=str(pylucid_src_path) 

).verbose_output(check=True) 

# print(output) 

 

# Check if change was ok: 

output = VerboseSubprocess( 

"git", "remote", "-v", 

cwd=str(pylucid_src_path) 

).verbose_output(check=True) 

# print(output) 

self.assertIn("https://github.com/jedie/PyLucid.git", output) 

self.assertNotIn("git@github.com", output) 

 

output = self.pylucid_admin_run("change_editable_address") 

print(output) 

 

self.assertIn("git@github.com:jedie/PyLucid.git", output)