This repository was archived by the owner on Mar 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathpython.test.ts
More file actions
46 lines (39 loc) · 1.55 KB
/
python.test.ts
File metadata and controls
46 lines (39 loc) · 1.55 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
import * as assert from 'assert'
import { pythonSpec, relativeImportPath } from './python'
import { nilFilterContext, nilResult } from './spec.test'
const fileContent = `
import .bar
from .baz.bonk import honk
from ..bonk.quux import ronk
import a.b.c.quux
`
describe('pythonSpec', () => {
it('filters definitions', () => {
const results = [
{ ...nilResult, file: 'a/b/c/bar.py' },
{ ...nilResult, file: 'a/b/c/baz/bonk.py' },
{ ...nilResult, file: 'a/b/bonk/quux.py' },
{ ...nilResult, file: 'a/b/c/quux.py' },
// incorrect file
{ ...nilResult, file: 'a/b/c/baz.py' },
// incorrect paths
{ ...nilResult, file: 'a/b/quux.py' },
{ ...nilResult, file: 'x/y/z/quux.py' },
]
const filtered = pythonSpec.filterDefinitions?.(results, {
...nilFilterContext,
filePath: 'a/b/c/foo.py',
fileContent,
})
assert.deepStrictEqual(filtered, [results[0], results[1], results[2], results[3]])
})
})
describe('relativeImportPath', () => {
it('converts relative import to path', () => {
assert.strictEqual(relativeImportPath('a/b/c.py', 'foo'), undefined)
assert.strictEqual(relativeImportPath('a/b/c.py', '.foo'), 'a/b/foo')
assert.strictEqual(relativeImportPath('a/b/c.py', '.foo.bar'), 'a/b/foo/bar')
assert.strictEqual(relativeImportPath('a/b/c.py', '..foo.bar'), 'a/foo/bar')
assert.strictEqual(relativeImportPath('a/b/c.py', '....foo'), '../foo')
})
})