@@ -17,18 +17,17 @@ class GoProject:
1717 """
1818 A representation of a Go project and its local environment.
1919 """
20- def __init__ (self , go_dir : str , directory : str , env : dict ):
20+ def __init__ (self , go_dir : Path , directory : Path , env : dict ):
2121 self .go_dir = go_dir
2222 self .directory = directory
2323 self .env = env
2424
25-
2625 def get_go_dir_contents (self ) -> str :
2726 """
2827 List the contents in the go directory.
2928
30- Note that this only looks at the name and path of the filesm ignoring
31- their actual contents!
29+ Note that this only looks at the name and path of the files, ignoring
30+ their actual contents.
3231 """
3332 h = hashlib .new ("md5" )
3433 for root , _ , files in os .walk (self .go_dir ):
@@ -65,7 +64,13 @@ def test_go_no_change(new_go_project):
6564 Test that certain `go` commands relied on by Supply-Chain Firewall
6665 not to error or modify the local installation state indeed have these properties.
6766 """
68- def _test_go_no_change (project : GoProject , base_go : GoProject , local_init_state : str , global_init_state : str , command : list ) -> bool :
67+ def _test_go_no_change (
68+ project : GoProject ,
69+ base_go : GoProject ,
70+ local_init_state : str ,
71+ global_init_state : str ,
72+ command : list
73+ ) -> bool :
6974 """
7075 Tests that a given Poetry command does not encounter any errors and does not
7176 modify the local installation state when run in the context of a given project.
@@ -76,16 +81,19 @@ def _test_go_no_change(project: GoProject, base_go: GoProject, local_init_state:
7681 return go_show (project ) == local_init_state and base_go .get_go_dir_contents () == global_init_state
7782
7883 test_cases = []
79- for command in [ "build" , "generate" , "get" , "install" , "mod" , "run" ] :
80- for param in [ "-h" , "-help" ] :
84+ for command in { "build" , "generate" , "get" , "install" , "mod" , "run" } :
85+ for param in { "-h" , "-help" } :
8186 test_cases .append (["go" , command , param ])
8287
83- base_go = GoProject (get_gopath (), "" , {})
88+ base_go = GoProject (get_gopath (), Path ( "" ) , {})
8489 global_init_state = base_go .get_go_dir_contents ()
8590
8691 local_init_state = go_show (new_go_project )
8792
88- assert all (_test_go_no_change (new_go_project , base_go , local_init_state , global_init_state , command ) for command in test_cases )
93+ assert all (
94+ _test_go_no_change (new_go_project , base_go , local_init_state , global_init_state , command )
95+ for command in test_cases
96+ )
8997
9098
9199def go_show (project : GoProject ) -> str :
@@ -103,15 +111,15 @@ def go_show(project: GoProject) -> str:
103111 return go_show .stdout .lower ()
104112
105113
106- def get_gopath () -> str :
114+ def get_gopath () -> Path :
107115 """
108116 Retrieve the default path where go install packages.
109117 """
110118 gopath = subprocess .run (["go" , "env" , "GOPATH" ], check = True , text = True , capture_output = True )
111- return gopath .stdout .strip ()
119+ return Path ( gopath .stdout .strip () )
112120
113121
114- def _init_go_env (directory ) -> ( Path , dict ) :
122+ def _init_go_env (directory ) -> tuple [ Path , dict ] :
115123 """
116124 Initialize a fresh Go environment in `directory` and return both the path
117125 used by go and the environment variables that should be provided to
0 commit comments