예제 #1
0
        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"));
        }
예제 #2
0
        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));
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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());
        }