예제 #1
0
        public void setupFinders()
        {
            var repo = new InjectedModuleRepository();

            fooModule = PyModule.Create("foo");

            barModule  = PyModule.Create("bar");
            fooThing   = PyString.Create("FooThing");
            otherThing = PyString.Create("OtherThing");
            fooModule.__dict__.Add("bar", barModule);
            fooModule.__dict__.Add("FooThing", fooThing);
            fooModule.__dict__.Add("OtherThing", otherThing);

            foo2Module = PyModule.Create("foo2");

            repo.AddNewModuleRoot(fooModule);
            repo.AddNewModuleRoot(foo2Module);

            moduleFinders = new List <ISpecFinder>();
            moduleFinders.Add(repo);
        }
예제 #2
0
        public async Task RootLevel()
        {
            var repo      = new InjectedModuleRepository();
            var fooModule = PyModule.Create("foo");

            repo.AddNewModuleRoot(fooModule);

            var fooSpec = repo.find_spec(null, "foo", null, null);

            Assert.That(fooSpec, Is.Not.Null);

            var fooLoaded = await fooSpec.Loader.Load(null, null, fooSpec);

            Assert.That(fooLoaded, Is.EqualTo(fooModule));
        }
예제 #3
0
        public async Task SecondLevelNonModule()
        {
            // Exception should be something like:
            // ModuleNotFoundError: No module named 'foo.bar.barstring'; 'foo.bar.barstring' is not a package
            // They would be forced to use the "from foo.bar import barstring"
            var repo      = new InjectedModuleRepository();
            var fooModule = PyModule.Create("foo");
            var barModule = PyModule.Create("bar");
            var barString = PyString.Create("bar string");

            barModule.__dict__.Add("barstring", barString);
            fooModule.__dict__.Add("bar", barModule);
            repo.AddNewModuleRoot(fooModule);

            var barStringSpec = repo.find_spec(null, "foo.bar.barstring", null, null);

            Assert.That(barStringSpec, Is.Not.Null);

            var barStringLoaded = await barStringSpec.Loader.Load(null, null, barStringSpec);

            Assert.That(barStringLoaded, Is.EqualTo(barString));
        }
예제 #4
0
        public async Task SecondLevel()
        {
            var repo      = new InjectedModuleRepository();
            var fooModule = PyModule.Create("foo");
            var barModule = PyModule.Create("bar");

            fooModule.__dict__.Add("bar", barModule);
            repo.AddNewModuleRoot(fooModule);

            var fooSpec = repo.find_spec(null, "foo", null, null);
            var barSpec = repo.find_spec(null, "foo.bar", null, null);

            Assert.That(fooSpec, Is.Not.Null);
            Assert.That(barSpec, Is.Not.Null);

            var fooLoaded = await fooSpec.Loader.Load(null, null, fooSpec);

            var barLoaded = await barSpec.Loader.Load(null, null, barSpec);

            Assert.That(fooLoaded, Is.EqualTo(fooModule));
            Assert.That(barLoaded, Is.EqualTo(barModule));
        }