2018-03-26 19:05:54 +03:00
|
|
|
{-# LANGUAGE OverloadedLists #-}
|
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-23 20:11:29 +03:00
|
|
|
env <- findEnv <$> evaluate "main.py"
|
|
|
|
env `shouldBe` [ (qualifiedName ["a", "foo"], addr 0)
|
|
|
|
, (qualifiedName ["b", "c", "baz"], addr 1)
|
|
|
|
]
|
2018-03-10 02:01:29 +03:00
|
|
|
|
2018-03-10 02:16:07 +03:00
|
|
|
it "imports with aliases" $ do
|
2018-03-23 20:11:29 +03:00
|
|
|
env <- findEnv <$> evaluate "main1.py"
|
|
|
|
env `shouldBe` [ (qualifiedName ["b", "foo"], addr 0)
|
|
|
|
, (qualifiedName ["e", "baz"], addr 1)
|
|
|
|
]
|
2018-03-10 02:16:07 +03:00
|
|
|
|
|
|
|
it "imports using 'from' syntax" $ do
|
2018-03-23 20:11:29 +03:00
|
|
|
env <- findEnv <$> evaluate "main2.py"
|
|
|
|
env `shouldBe` [ (qualifiedName ["foo"], addr 0)
|
|
|
|
, (qualifiedName ["bar"], addr 1)
|
|
|
|
]
|
2018-03-10 02:16:07 +03:00
|
|
|
|
2018-03-23 18:01:13 +03:00
|
|
|
it "subclasses" $ do
|
2018-03-23 20:11:29 +03:00
|
|
|
v <- findValue <$> evaluate "subclass.py"
|
2018-03-24 00:40:22 +03:00
|
|
|
v `shouldBe` Right (Right (Right (injValue (String "\"bar\""))))
|
2018-03-23 18:01:13 +03:00
|
|
|
|
|
|
|
it "handles multiple inheritance left-to-right" $ do
|
2018-03-23 20:11:29 +03:00
|
|
|
v <- findValue <$> evaluate "multiple_inheritance.py"
|
2018-03-24 00:40:22 +03:00
|
|
|
v `shouldBe` Right (Right (Right (injValue (String "\"foo!\""))))
|
2018-03-23 18:01:13 +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-23 20:11:29 +03:00
|
|
|
evaluate entry = 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
|
|
|
]
|