This repository was archived by the owner on Jun 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathtest_extractor.py
More file actions
70 lines (58 loc) · 1.87 KB
/
test_extractor.py
File metadata and controls
70 lines (58 loc) · 1.87 KB
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
from codegate.utils.package_extractor import PackageExtractor
def test_extractor_javascript():
js_code = """
import { createApp } from '@vue/compat';
import React from 'react';
import { useState } from 'react';
import lodash from 'lodash';
import express from 'express';
import { Router } from 'express';
import somethingElse from '@something/somethingelse';
"""
packages = PackageExtractor.extract_packages(js_code, "javascript")
assert sorted(packages) == [
"@something/somethingelse",
"@vue/compat",
"express",
"lodash",
"react",
]
def test_extractor_go():
go_code = """
package main
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/your/module/types"
)
"""
packages = PackageExtractor.extract_packages(go_code, "go")
assert sorted(packages) == [
"github.com/stretchr/testify/assert",
"github.com/your/module/types",
"testing",
]
def test_extractor_python():
python_code = """
import pandas
from codegate.utils import test
import numpy as np
"""
packages = PackageExtractor.extract_packages(python_code, "python")
assert sorted(packages) == ["codegate", "numpy", "pandas"]
def test_extractor_java():
java_code = """
import java.util.List;
import java.io.File;
import com.example.project.MyClass;
"""
packages = PackageExtractor.extract_packages(java_code, "java")
assert sorted(packages) == ["com.example.project.MyClass", "java.io.File", "java.util.List"]
def test_extractor_rust():
rust_code = """
use rust_decimal_macros::dec;
use rust_decimal::prelude::*;
use inner::foo as bar;
"""
packages = PackageExtractor.extract_packages(rust_code, "rust")
assert sorted(packages) == ["inner", "rust_decimal", "rust_decimal_macros"]