public void ExecuteImportFromCommand() { ImportFromCommand importcmd = new ImportFromCommand("setvars", new string[] { "one", "two" }); Machine machine = new Machine(); importcmd.Execute(machine.Environment); Assert.AreEqual(1, machine.Environment.GetValue("one")); Assert.AreEqual(2, machine.Environment.GetValue("two")); }
public void ImportFileTypeFromSystemIONamespace() { ImportFromCommand importcmd = new ImportFromCommand("System.IO", new string[] { "File" }); Machine machine = new Machine(); importcmd.Execute(machine.Environment); var result = machine.Environment.GetValue("File"); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(Type)); }
public void RaiseWhenImportFromModuleDoesNotExist() { ImportFromCommand importcmd = new ImportFromCommand("spam"); Machine machine = new Machine(); try { importcmd.Execute(machine.Environment); Assert.Fail("Exception expected"); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ImportError)); Assert.AreEqual("No module named spam", ex.Message); } }
public void CompileImportFromCommand() { Parser parser = new Parser("from module import a, b"); ICommand command = parser.CompileCommand(); Assert.IsNotNull(command); Assert.IsInstanceOfType(command, typeof(ImportFromCommand)); ImportFromCommand impcmd = (ImportFromCommand)command; Assert.AreEqual("module", impcmd.ModuleName); Assert.IsNotNull(impcmd.Names); Assert.AreEqual(2, impcmd.Names.Count); Assert.AreEqual("a", impcmd.Names.First()); Assert.AreEqual("b", impcmd.Names.Skip(1).First()); }