55from collections import Mapping , MutableMapping , Sequence
66import sys
77import copy
8- from typing import Any , Dict , List , Text , Union # pylint:disable=unused-import
8+ from typing import (Any , Dict , List , Optional , # pylint:disable=unused-import
9+ Text , Union )
910import ruamel .yaml
1011
11- def main (): # type: () -> int
12+
13+ def main (args = None ): # type: (Optional[List[str]]) -> int
1214 """Main function."""
13- for path in sys .argv [1 :]:
15+ if not args :
16+ args = sys .argv [1 :]
17+ assert args is not None
18+ for path in args :
1419 with open (path ) as entry :
1520 document = ruamel .yaml .safe_load (entry )
1621 if ('cwlVersion' in document
@@ -36,6 +41,7 @@ def draft3_to_v1_0(document): # type: (Dict[Text, Any]) -> None
3641 value [index ] = _draft3_to_v1_0 (entry )
3742 document ['cwlVersion' ] = 'v1.0'
3843
44+
3945def _draft3_to_v1_0 (document ):
4046 # type: (MutableMapping[Text, Any]) -> MutableMapping[Text, Any]
4147 """Inner loop for transforming draft-3 to v1.0."""
@@ -144,7 +150,7 @@ def shorten_type(type_obj): # type: (List[Any]) -> Union[Text, List[Any]]
144150 if 'null' in new_type :
145151 type_copy = copy .deepcopy (new_type )
146152 type_copy .remove ('null' )
147- if isinstance (type_copy [0 ], Text ):
153+ if isinstance (type_copy [0 ], ( str , Text ) ):
148154 return type_copy [0 ] + '?'
149155 return new_type
150156
@@ -160,4 +166,4 @@ def clean_secondary_files(document):
160166
161167
162168if __name__ == "__main__" :
163- sys .exit (main ())
169+ sys .exit (main (sys . argv [: 1 ] ))
0 commit comments