@@ -539,3 +539,114 @@ def test_gist_secret():
539539
540540 provider = GistRepoProvider (spec = spec , allow_secret_gist = True )
541541 assert IOLoop ().run_sync (provider .get_resolved_ref ) is not None
542+
543+
544+ @pytest .mark .parametrize (
545+ "provider,url,groupdict" ,
546+ [
547+ (
548+ GitHubRepoProvider ,
549+ "https://github.com/binder-examples/conda" ,
550+ {"repo" : "binder-examples/conda" , "filepath" : None , "ref" : None },
551+ ),
552+ (
553+ GitHubRepoProvider ,
554+ "https://github.com/binder-examples/conda/blob/main/index.ipynb" ,
555+ {"repo" : "binder-examples/conda" , "ref" : "main" , "filepath" : "index.ipynb" },
556+ ),
557+ (
558+ GitHubRepoProvider ,
559+ "https://github.com/binder-examples/conda/tree/main/.github/workflows" ,
560+ {
561+ "repo" : "binder-examples/conda" ,
562+ "ref" : "main" ,
563+ "urlpath" : ".github/workflows" ,
564+ },
565+ ),
566+ (GitHubRepoProvider , "https://github.com/binder-examples/conda/pulls" , None ),
567+ (
568+ GitLabRepoProvider ,
569+ "https://gitlab.com/owner/repo" ,
570+ {
571+ "repo" : "owner/repo" ,
572+ "ref" : None ,
573+ "filepath" : None ,
574+ },
575+ ),
576+ (
577+ GitLabRepoProvider ,
578+ "https://gitlab.com/owner/repo/-/tree/branch/folder?ref_type=heads" ,
579+ {"repo" : "owner/repo" , "ref" : "branch" , "urlpath" : "folder?ref_type=heads" },
580+ ),
581+ (
582+ GitLabRepoProvider ,
583+ "https://gitlab.com/owner/repo/-/blob/branch/README.md?ref_type=heads" ,
584+ {
585+ "repo" : "owner/repo" ,
586+ "ref" : "branch" ,
587+ "filepath" : "README.md?ref_type=heads" ,
588+ },
589+ ),
590+ (
591+ GitLabRepoProvider ,
592+ "https://gitlab.com/owner/project/repo" ,
593+ {
594+ "repo" : "owner/project/repo" ,
595+ "ref" : None ,
596+ "filepath" : None ,
597+ },
598+ ),
599+ (
600+ GitLabRepoProvider ,
601+ "https://gitlab.com/owner/project/repo/-/tree/branch/folder?ref_type=heads" ,
602+ {
603+ "repo" : "owner/project/repo" ,
604+ "ref" : "branch" ,
605+ "urlpath" : "folder?ref_type=heads" ,
606+ },
607+ ),
608+ (
609+ GitLabRepoProvider ,
610+ "https://gitlab.com/owner/project/repo/-/blob/branch/README.md?ref_type=heads" ,
611+ {
612+ "repo" : "owner/project/repo" ,
613+ "ref" : "branch" ,
614+ "filepath" : "README.md?ref_type=heads" ,
615+ },
616+ ),
617+ (
618+ GitLabRepoProvider ,
619+ "https://gitlab.com/owner/repo/-/merge_requests/123" ,
620+ None ,
621+ ),
622+ (
623+ GistRepoProvider ,
624+ "https://gist.github.com/owner/0123456789abcde0123456789abcde01" ,
625+ {
626+ "repo" : "owner/0123456789abcde0123456789abcde01" ,
627+ "ref" : None ,
628+ },
629+ ),
630+ (
631+ GistRepoProvider ,
632+ "https://gist.github.com/owner/0123456789abcde0123456789abcde01/sha" ,
633+ {
634+ "repo" : "owner/0123456789abcde0123456789abcde01" ,
635+ "ref" : "sha" ,
636+ },
637+ ),
638+ (GistRepoProvider , "https://gist.github.com/owner" , None ),
639+ ],
640+ )
641+ def test_provider_regex_detect (provider , url , groupdict ):
642+ regex_js = provider .regex_detect
643+ regex_py = [r .replace ("(?<" , "(?P<" ) for r in regex_js ]
644+ m = None
645+ for r in regex_py :
646+ m = re .match (r , url )
647+ if m :
648+ break
649+ if groupdict :
650+ assert m .groupdict () == groupdict
651+ else :
652+ assert not m
0 commit comments