public void Name_ExpressionIsImportFollowedByName_MatchesNameAfterImport()
		{
			PythonImportExpression expression = new PythonImportExpression("import abc");
			PythonImportModuleResolveResult result = new PythonImportModuleResolveResult(expression);
			string expectedName = "abc";
			Assert.AreEqual(expectedName, result.Name);
		}
		public void Init()
		{
			string code = "from datetime import";
			importExpression = new PythonImportExpression(code);
			resolveResult = new PythonImportModuleResolveResult(importExpression);
			
			projectContent = new MockProjectContent();
		}
		public void Init()
		{
			string code = "from math import";
			importExpression = new PythonImportExpression(code);
			resolveResult = new PythonImportModuleResolveResult(importExpression);
			
			projectContent = new MockProjectContent();
			completionItems = resolveResult.GetCompletionData(projectContent);
		}
		public void GetCompletionData_WhenImportNameIsEmptyString_ReturnsStandardMathPythonModule()
		{
			PythonImportExpression expression = new PythonImportExpression(String.Empty);
			PythonImportModuleResolveResult result = new PythonImportModuleResolveResult(expression);
			MockProjectContent projectContent = new MockProjectContent();
			
			List<ICompletionEntry> completionItems = result.GetCompletionData(projectContent);
			NamespaceEntry mathNamespaceCompletionItem = new NamespaceEntry("math");
			Assert.Contains(mathNamespaceCompletionItem, completionItems);
		}
		public void GetCompletionData_ClonedPythonModuleResult_ReturnsSameCompletionItems()
		{
			PythonImportExpression expression = new PythonImportExpression(String.Empty);
			PythonImportModuleResolveResult result = new PythonImportModuleResolveResult(expression);
			ResolveResult clonedResult = result.Clone();
			MockProjectContent projectContent = new MockProjectContent();
			
			List<ICompletionEntry> completionItems = clonedResult.GetCompletionData(projectContent);
			NamespaceEntry mathNamespaceCompletionItem = new NamespaceEntry("math");
			Assert.Contains(mathNamespaceCompletionItem, completionItems);
		}
		public ResolveResult Resolve(PythonResolverContext resolverContext)
		{
			if (IsNamespace(resolverContext.ExpressionResult)) {
				PythonImportExpression importExpression = new PythonImportExpression(resolverContext.Expression);
				PythonImportExpressionContext context = resolverContext.ExpressionContext as PythonImportExpressionContext;
				context.HasFromAndImport = importExpression.HasFromAndImport;
				
				return new PythonImportModuleResolveResult(importExpression);
			}
			return null;
		}
Exemple #7
0
        public ResolveResult Resolve(PythonResolverContext resolverContext)
        {
            if (IsNamespace(resolverContext.ExpressionResult))
            {
                PythonImportExpression        importExpression = new PythonImportExpression(resolverContext.Expression);
                PythonImportExpressionContext context          = resolverContext.ExpressionContext as PythonImportExpressionContext;
                context.HasFromAndImport = importExpression.HasFromAndImport;

                return(new PythonImportModuleResolveResult(importExpression));
            }
            return(null);
        }
		public void Init()
		{
			string code = "from System import Console";
			importExpression = new PythonImportExpression(code);
			resolveResult = new PythonImportModuleResolveResult(importExpression);
			
			projectContent = new MockProjectContent();
			DefaultCompilationUnit unit = new DefaultCompilationUnit(projectContent);
			DefaultClass c = new DefaultClass(unit, "Test");
			List<ICompletionEntry> namespaceItems = new List<ICompletionEntry>();
			namespaceItems.Add(c);
			projectContent.AddExistingNamespaceContents("System", namespaceItems);
		}
        bool IsImportExpression(string text)
        {
            if (PythonImportExpression.IsImportExpression(text, expressionRange.End))
            {
                return(true);
            }

            if (IsSpaceCharacterBeforeExpression(text, expressionRange))
            {
                if (PythonImportExpression.IsImportExpression(text, expressionRange.Start))
                {
                    return(true);
                }
            }
            return(false);
        }
		public void ModuleNameReturnedIsSystemForImportSystemExpression()
		{
			PythonImportExpression expression = new PythonImportExpression(engine, "import System");
			Assert.AreEqual("System", expression.Module);
		}
		public void Init()
		{
			string code = "from System import Console";
			importExpression = new PythonImportExpression(code);
		}
		public void ModuleNameIsEmptyStringWhenExpressionIsEmptyString()
		{
			PythonImportExpression expression = new PythonImportExpression(engine, String.Empty);
			Assert.AreEqual(String.Empty, expression.Module);
		}
		public void Init()
		{
			string text = "from System import ";
			expression = new PythonImportExpression(Python.CreateEngine(), text);
		}
		public void Init()
		{
			string text = "import System.Console";
			importExpression = new PythonImportExpression(Python.CreateEngine(), text);
		}
		public void FromModuleNameIsEmptyWhenOnlyFromIsInExpression()
		{
			PythonImportExpression expression = new PythonImportExpression(engine, "from");
			Assert.AreEqual(String.Empty, expression.Module);
			Assert.IsFalse(expression.HasFromAndImport);
		}
		public void FromModuleNameIsSystemForFromSystemExpressionWithWhitespaceBetweenImportAndSystem()
		{
			PythonImportExpression expression = new PythonImportExpression(engine, "from  \t  System");
			Assert.AreEqual("System", expression.Module);
			Assert.IsFalse(expression.HasFromAndImport);
		}
		public void ModuleNameReturnedIsSystemForImportSystemExpressionWithWhitespaceBetweenImportAndSystem()
		{
			string code = "import  \t  System";
			PythonImportExpression expression = new PythonImportExpression(engine, code);
			Assert.AreEqual("System", expression.Module);
		}
 public PythonImportModuleResolveResult(PythonImportExpression expression)
     : base(null, null, null)
 {
     this.expression = expression;
 }
		public void HasIdentifierReturnsFalseForFromMathImportWithoutIdentfier()
		{
			PythonImportExpression expression = new PythonImportExpression(engine, "from math import");
			Assert.IsFalse(expression.HasIdentifier);
		}