2018-03-10 02:01:29 +03:00
|
|
|
{-# LANGUAGE TypeApplications #-}
|
2018-03-13 20:26:28 +03:00
|
|
|
module Analysis.Python.Spec (spec) where
|
2018-03-10 02:01:29 +03:00
|
|
|
|
2018-03-13 20:26:28 +03:00
|
|
|
import Data.Abstract.Value
|
|
|
|
import Data.Map
|
2018-03-13 20:59:06 +03:00
|
|
|
|
2018-03-10 02:01:29 +03:00
|
|
|
import SpecHelpers
|
|
|
|
|
2018-03-10 03:24:23 +03:00
|
|
|
|
2018-03-10 02:01:29 +03:00
|
|
|
spec :: Spec
|
|
|
|
spec = parallel $ do
|
2018-03-10 02:55:04 +03:00
|
|
|
describe "evalutes Python" $ do
|
2018-03-10 02:16:07 +03:00
|
|
|
it "imports" $ do
|
2018-03-14 21:38:49 +03:00
|
|
|
env <- evaluate "main.py"
|
2018-03-10 02:01:29 +03:00
|
|
|
let expectedEnv = Environment $ fromList
|
|
|
|
[ (qualifiedName ["a", "foo"], addr 0)
|
|
|
|
, (qualifiedName ["b", "c", "baz"], addr 1)
|
|
|
|
]
|
2018-03-14 21:38:49 +03:00
|
|
|
env `shouldBe` expectedEnv
|
2018-03-10 02:01:29 +03:00
|
|
|
|
2018-03-10 02:16:07 +03:00
|
|
|
it "imports with aliases" $ do
|
2018-03-14 21:38:49 +03:00
|
|
|
env <- evaluate "main1.py"
|
2018-03-10 02:16:07 +03:00
|
|
|
let expectedEnv = Environment $ fromList
|
|
|
|
[ (qualifiedName ["b", "foo"], addr 0)
|
|
|
|
, (qualifiedName ["e", "baz"], addr 1)
|
|
|
|
]
|
2018-03-14 21:38:49 +03:00
|
|
|
env `shouldBe` expectedEnv
|
2018-03-10 02:16:07 +03:00
|
|
|
|
|
|
|
it "imports using 'from' syntax" $ do
|
2018-03-14 21:38:49 +03:00
|
|
|
env <- evaluate "main2.py"
|
2018-03-10 02:16:07 +03:00
|
|
|
let expectedEnv = Environment $ fromList
|
|
|
|
[ (qualifiedName ["foo"], addr 0)
|
|
|
|
, (qualifiedName ["bar"], addr 1)
|
|
|
|
]
|
2018-03-14 21:38:49 +03:00
|
|
|
env `shouldBe` expectedEnv
|
2018-03-10 02:16:07 +03:00
|
|
|
|
2018-03-10 02:01:29 +03:00
|
|
|
where
|
|
|
|
addr = Address . Precise
|
2018-03-10 03:24:23 +03:00
|
|
|
fixtures = "test/fixtures/python/analysis/"
|
2018-03-15 17:23:50 +03:00
|
|
|
evaluate entry = snd . fst . fst . fst . fst <$>
|
2018-03-15 23:04:36 +03:00
|
|
|
evaluateFiles pythonParser
|
2018-03-10 03:24:23 +03:00
|
|
|
[ fixtures <> entry
|
|
|
|
, fixtures <> "a.py"
|
|
|
|
, fixtures <> "b/c.py"
|
2018-03-10 02:16:07 +03:00
|
|
|
]
|