cubicweb/test/unittest_cwconfig.py
branch3.25
changeset 12165 127f7da447a4
parent 12119 c4ed3f6463f6
child 12272 36032de96867
equal deleted inserted replaced
12162:c1d7c0f66210 12165:127f7da447a4
   407         # not a python package
   407         # not a python package
   408         self.assertEqual(list(_expand_modname('lib.e')), [])
   408         self.assertEqual(list(_expand_modname('lib.e')), [])
   409         self.assertEqual(list(_expand_modname('lib.a')), [
   409         self.assertEqual(list(_expand_modname('lib.a')), [
   410             ('lib.a', join(tempdir, 'a.py')),
   410             ('lib.a', join(tempdir, 'a.py')),
   411         ])
   411         ])
   412         # lib.b.d (subpackage) not to be imported
   412         # lib.b.d should be imported
   413         self.assertEqual(list(_expand_modname('lib.b')), [
   413         self.assertEqual(list(_expand_modname('lib.b')), [
       
   414             ('lib.b', join(tempdir, 'b', '__init__.py')),
       
   415             ('lib.b.a', join(tempdir, 'b', 'a.py')),
       
   416             ('lib.b.c', join(tempdir, 'b', 'c.py')),
       
   417             ('lib.b.d', join(tempdir, 'b', 'd', '__init__.py')),
       
   418         ])
       
   419         # lib.b.d should not be imported without recursive mode
       
   420         self.assertEqual(list(_expand_modname('lib.b', recursive=False)), [
   414             ('lib.b', join(tempdir, 'b', '__init__.py')),
   421             ('lib.b', join(tempdir, 'b', '__init__.py')),
   415             ('lib.b.a', join(tempdir, 'b', 'a.py')),
   422             ('lib.b.a', join(tempdir, 'b', 'a.py')),
   416             ('lib.b.c', join(tempdir, 'b', 'c.py')),
   423             ('lib.b.c', join(tempdir, 'b', 'c.py')),
   417         ])
   424         ])
   418         self.assertEqual(list(_expand_modname('lib')), [
   425         self.assertEqual(list(_expand_modname('lib')), [
   419             ('lib', join(tempdir, '__init__.py')),
   426             ('lib', join(tempdir, '__init__.py')),
   420             ('lib.a', join(tempdir, 'a.py')),
   427             ('lib.a', join(tempdir, 'a.py')),
       
   428             ('lib.b', join(tempdir, 'b', '__init__.py')),
       
   429             ('lib.b.a', join(tempdir, 'b', 'a.py')),
       
   430             ('lib.b.c', join(tempdir, 'b', 'c.py')),
       
   431             ('lib.b.d', join(tempdir, 'b', 'd', '__init__.py')),
   421             ('lib.c', join(tempdir, 'c.py')),
   432             ('lib.c', join(tempdir, 'c.py')),
   422         ])
   433         ])
   423         for source in (
   434         for source in (
   424             join(tempdir, 'c.py'),
   435             join(tempdir, 'c.py'),
   425             join(tempdir, 'b', 'c.py'),
   436             join(tempdir, 'b', 'c.py'),
       
   437             join(tempdir, 'b', 'd', '__init__.py'),
   426         ):
   438         ):
   427             if not PY3:
   439             if not PY3:
   428                 # ensure pyc file exists.
   440                 # ensure pyc file exists.
   429                 # Doesn't required for PY3 since it create __pycache__
   441                 # Doesn't required for PY3 since it create __pycache__
   430                 # directory and will not import if source file doesn't
   442                 # directory and will not import if source file doesn't
   439             ('lib.b.a', join(tempdir, 'b', 'a.py')),
   451             ('lib.b.a', join(tempdir, 'b', 'a.py')),
   440         ])
   452         ])
   441         self.assertEqual(list(_expand_modname('lib')), [
   453         self.assertEqual(list(_expand_modname('lib')), [
   442             ('lib', join(tempdir, '__init__.py')),
   454             ('lib', join(tempdir, '__init__.py')),
   443             ('lib.a', join(tempdir, 'a.py')),
   455             ('lib.a', join(tempdir, 'a.py')),
       
   456             ('lib.b', join(tempdir, 'b', '__init__.py')),
       
   457             ('lib.b.a', join(tempdir, 'b', 'a.py')),
   444         ])
   458         ])
   445 
   459 
   446     @templibdir
   460     @templibdir
   447     def test_schema_modnames(self, libdir):
   461     def test_schema_modnames(self, libdir):
   448         for filepath in (
   462         for filepath in (
   449             join(libdir, 'schema.py'),
   463             join(libdir, 'schema.py'),
   450             join(libdir, 'cubicweb_foo', '__init__.py'),
   464             join(libdir, 'cubicweb_foo', '__init__.py'),
   451             join(libdir, 'cubicweb_foo', 'schema', '__init__.py'),
   465             join(libdir, 'cubicweb_foo', 'schema', '__init__.py'),
   452             join(libdir, 'cubicweb_foo', 'schema', 'a.py'),
   466             join(libdir, 'cubicweb_foo', 'schema', 'a.py'),
   453             join(libdir, 'cubicweb_foo', 'schema', 'b.py'),
   467             join(libdir, 'cubicweb_foo', 'schema', 'b.py'),
       
   468             # subpackages should not be loaded
       
   469             join(libdir, 'cubicweb_foo', 'schema', 'c', '__init__.py'),
   454             join(libdir, 'cubes', '__init__.py'),
   470             join(libdir, 'cubes', '__init__.py'),
   455             join(libdir, 'cubes', 'bar', '__init__.py'),
   471             join(libdir, 'cubes', 'bar', '__init__.py'),
   456             join(libdir, 'cubes', 'bar', 'schema.py'),
   472             join(libdir, 'cubes', 'bar', 'schema.py'),
   457             join(libdir, '_instance_dir', 'data1', 'schema.py'),
   473             join(libdir, '_instance_dir', 'data1', 'schema.py'),
   458             join(libdir, '_instance_dir', 'data2', 'noschema.py'),
   474             join(libdir, '_instance_dir', 'data2', 'noschema.py'),
   490         for filepath in (
   506         for filepath in (
   491             join(libdir, 'entities.py'),
   507             join(libdir, 'entities.py'),
   492             join(libdir, 'cubicweb_foo', '__init__.py'),
   508             join(libdir, 'cubicweb_foo', '__init__.py'),
   493             join(libdir, 'cubicweb_foo', 'entities', '__init__.py'),
   509             join(libdir, 'cubicweb_foo', 'entities', '__init__.py'),
   494             join(libdir, 'cubicweb_foo', 'entities', 'a.py'),
   510             join(libdir, 'cubicweb_foo', 'entities', 'a.py'),
       
   511             # subpackages should be loaded recursively
       
   512             join(libdir, 'cubicweb_foo', 'entities', 'b', '__init__.py'),
       
   513             join(libdir, 'cubicweb_foo', 'entities', 'b', 'a.py'),
       
   514             join(libdir, 'cubicweb_foo', 'entities', 'b', 'c', '__init__.py'),
   495             join(libdir, 'cubicweb_foo', 'hooks.py'),
   515             join(libdir, 'cubicweb_foo', 'hooks.py'),
   496             join(libdir, 'cubes', '__init__.py'),
   516             join(libdir, 'cubes', '__init__.py'),
   497             join(libdir, 'cubes', 'bar', '__init__.py'),
   517             join(libdir, 'cubes', 'bar', '__init__.py'),
   498             join(libdir, 'cubes', 'bar', 'hooks.py'),
   518             join(libdir, 'cubes', 'bar', 'hooks.py'),
   499             join(libdir, '_instance_dir', 'data1', 'entities.py'),
   519             join(libdir, '_instance_dir', 'data1', 'entities.py'),
   511             'cubicweb.entities.sources',
   531             'cubicweb.entities.sources',
   512             'cubicweb.entities.wfobjs',
   532             'cubicweb.entities.wfobjs',
   513             'cubes.bar.hooks',
   533             'cubes.bar.hooks',
   514             'cubicweb_foo.entities',
   534             'cubicweb_foo.entities',
   515             'cubicweb_foo.entities.a',
   535             'cubicweb_foo.entities.a',
       
   536             'cubicweb_foo.entities.b',
       
   537             'cubicweb_foo.entities.b.a',
       
   538             'cubicweb_foo.entities.b.c',
   516             'cubicweb_foo.hooks',
   539             'cubicweb_foo.hooks',
   517         ]
   540         ]
   518         # data1 has entities
   541         # data1 has entities
   519         with temp_config('data1', instance_dir, cubes_dir,
   542         with temp_config('data1', instance_dir, cubes_dir,
   520                          ('foo', 'bar')) as config:
   543                          ('foo', 'bar')) as config: