Esempio n. 1
0
    def test_directory_creation(self):
        """
        This tests assures we always know what is being created 
        in the framework directory
        """
        #assure we have a temp directory as HOME for testing
        testUserDir = tempfile.mkdtemp('_es_userdir')
        testUser = DummyUser(pw_dir=testUserDir)
        #assure we have a home directory setup
        self.assertTrue(os.path.isdir(testUser.getUserHome()))

        baseDir = testUser.getUserBaseDir()

        #check home is completely created
        #self.assertFalse(os.path.isdir(baseDir)) Basic dir structure is created when running a tool because of
        #history, so this doesn't apply anymore

        testUser.prepareDir()
        self.assertTrue(os.path.isdir(baseDir))
        print "Test user config dir in: ", testUser.getUserBaseDir()

        created_dirs = [
            testUser.getUserConfigDir(),
            testUser.getUserCacheDir(),
            testUser.getUserOutputDir(),
            testUser.getUserPlotsDir()
        ]
        print created_dirs
        for directory in created_dirs:
            self.assertTrue(os.path.isdir(directory))
Esempio n. 2
0
    def testd_ummy_user(self):
        """Be sure the dummy user is created as expected"""
        dummy_name = 'non-existing name'

        self.failUnlessRaises(Exception,
                              DummyUser,
                              random_home=True,
                              pw_dir='anything')

        d_user = DummyUser(random_home=True, pw_name=dummy_name)
        #populate the test directory as required
        d_user.prepareDir()
        self.assertEqual(dummy_name, d_user.getName())
        cfg_file = os.path.join(d_user.getUserBaseDir(), User.EVAL_SYS_CONFIG)

        #check configuration file writing
        self.assertFalse(os.path.isfile(cfg_file))
        cnfg = d_user.getUserConfig()
        cnfg.add_section("test_section")
        cnfg.set("test_section", 'some_key', 'a text value\nwith many\nlines!')
        d_user.writeConfig()
        self.assertTrue(os.path.isfile(cfg_file))
        fp = open(cfg_file, 'r')
        print fp.read()
        fp.close()

        #check configuration file reading
        fp = open(cfg_file, 'w')
        ##Note multi line values in the configuration file need to be indented...
        fp.write(
            "[test2]\nkey1 = 42\nkey2=Some\n\tmany\n\tlines=2\nkey3=%(key1)s0\n"
        )
        fp.close()
        cnfg = d_user.reloadConfig()
        self.assertTrue(cnfg.getint('test2', 'key1') == 42)
        #...but the indentation disappears when returned directly
        self.assertTrue(cnfg.get('test2', 'key2') == 'Some\nmany\nlines=2')
        self.assertTrue(cnfg.getint('test2', 'key3') == 420)

        d_user.cleanRandomHome()