示例#1
0
文件: test_io.py 项目: pombreda/osc2
 def test_mkdtemp3(self):
     """test __del__ method"""
     tmpdir = mkdtemp(dir=self._tmpdir)
     self.assertTrue(os.path.isdir(tmpdir))
     path = str(tmpdir)
     del tmpdir
     self.assertFalse(os.path.isdir(path))
示例#2
0
 def test_mkdtemp3(self):
     """test __del__ method"""
     tmpdir = mkdtemp(dir=self._tmpdir)
     self.assertTrue(os.path.isdir(tmpdir))
     path = str(tmpdir)
     del tmpdir
     self.assertFalse(os.path.isdir(path))
示例#3
0
 def test_mkdtemp4(self):
     """advanced __del__ semantics"""
     tmpdir = mkdtemp(dir=self._tmpdir)
     self.assertTrue(os.path.isdir(tmpdir))
     path = str(tmpdir)
     ref = tmpdir
     # ref still references the tmpdir, so the
     # actual object is not deleted
     del tmpdir
     self.assertTrue(os.path.isdir(path))
     del ref
     self.assertFalse(os.path.isdir(path))
示例#4
0
文件: test_io.py 项目: pombreda/osc2
 def test_mkdtemp4(self):
     """advanced __del__ semantics"""
     tmpdir = mkdtemp(dir=self._tmpdir)
     self.assertTrue(os.path.isdir(tmpdir))
     path = str(tmpdir)
     ref = tmpdir
     # ref still references the tmpdir, so the
     # actual object is not deleted
     del tmpdir
     self.assertTrue(os.path.isdir(path))
     del ref
     self.assertFalse(os.path.isdir(path))
示例#5
0
 def test_mkdtemp5(self):
     """test suffix and str operations"""
     tmpdir = mkdtemp(dir=self._tmpdir, suffix='foo')
     self.assertTrue(tmpdir.endswith('foo'))
     os.path.join(tmpdir, 'test')
     # test more str operations
     tmpdir + 'foo'
     'foo' + tmpdir
     self.assertTrue(len(tmpdir) > 0)
     self.assertTrue('foo' in tmpdir)
     self.assertEqual(''.join(tmpdir), tmpdir)
     # stat requires a "real" str (that is a str/unicode or buffer instance)
     os.stat(tmpdir)
示例#6
0
文件: test_io.py 项目: pombreda/osc2
 def test_mkdtemp5(self):
     """test suffix and str operations"""
     tmpdir = mkdtemp(dir=self._tmpdir, suffix='foo')
     self.assertTrue(tmpdir.endswith('foo'))
     os.path.join(tmpdir, 'test')
     # test more str operations
     tmpdir + 'foo'
     'foo' + tmpdir
     self.assertTrue(len(tmpdir) > 0)
     self.assertTrue('foo' in tmpdir)
     self.assertEqual(''.join(tmpdir), tmpdir)
     # stat requires a "real" str (that is a str/unicode or buffer instance)
     os.stat(tmpdir)
示例#7
0
 def test_wc_init2(self):
     """simple init wc external, empty storedir"""
     path = self.fixture_file('init')
     # we do not have to remove storedir later (cleanup happens
     # after each testcase)
     storedir = mkdtemp(dir=self._tmp_dir)
     storedir_lnk = self.fixture_file(path, '.osc')
     self._not_exists(path, '.osc')
     wc_init(path, ext_storedir=storedir)
     self._exists(path, '.osc')
     self.assertTrue(os.path.islink(storedir_lnk))
     self.assertTrue(os.path.isdir(storedir_lnk))
     self.assertEqual(sorted(os.listdir(storedir)), ['_version', 'data'])
示例#8
0
    def setUp(self):
        global EXPECTED_REQUESTS
        super(MockUrllib2Request, self).setUp()
        EXPECTED_REQUESTS = []
        self._orig_build_opener = urllib.request.build_opener

        def build_opener(*handlers):
            handlers += (MyHTTPHandler(exp_requests=EXPECTED_REQUESTS,
                                       fixtures_dir=self._fixtures_dir), )
            return self._orig_build_opener(*handlers)
        urllib.request.build_opener = build_opener
        self._tmp_dir = mkdtemp(prefix='osc_test')
        self._tmp_fixtures = os.path.join(self._tmp_dir, 'fixtures')
        shutil.copytree(self._fixtures_dir, self._tmp_fixtures, symlinks=True)
示例#9
0
    def setUp(self):
        global EXPECTED_REQUESTS
        super(MockUrllib2Request, self).setUp()
        EXPECTED_REQUESTS = []
        self._orig_build_opener = urllib2.build_opener

        def build_opener(*handlers):
            handlers += (MyHTTPHandler(exp_requests=EXPECTED_REQUESTS,
                                       fixtures_dir=self._fixtures_dir), )
            return self._orig_build_opener(*handlers)
        urllib2.build_opener = build_opener
        self._tmp_dir = mkdtemp(prefix='osc_test')
        self._tmp_fixtures = os.path.join(self._tmp_dir, 'fixtures')
        shutil.copytree(self._fixtures_dir, self._tmp_fixtures, symlinks=True)
示例#10
0
 def test_wc_init2(self):
     """simple init wc external, empty storedir"""
     path = self.fixture_file('init')
     # we do not have to remove storedir later (cleanup happens
     # after each testcase)
     storedir = mkdtemp(dir=self._tmp_dir)
     storedir_lnk = self.fixture_file(path, '.osc')
     self._not_exists(path, '.osc')
     wc_init(path, ext_storedir=storedir)
     self._exists(path, '.osc')
     self.assertTrue(os.path.islink(storedir_lnk))
     self.assertTrue(os.path.isdir(storedir_lnk))
     self.assertEqual(sorted(os.listdir(storedir)),
                      ['_version', 'data'])
示例#11
0
 def test1(self):
     """init a project dir"""
     tmpdir = mkdtemp(dir=self._tmp_dir)
     prj = Project.init(tmpdir, 'openSUSE:Tools',
                        'https://api.opensuse.org')
     prj_fname = os.path.join(tmpdir, '.osc', '_project')
     self.assertTrue(os.path.exists(prj_fname))
     self.assertEqual(open(prj_fname, 'r').read(), 'openSUSE:Tools\n')
     pkgs_fname = os.path.join(tmpdir, '.osc', '_packages')
     self.assertTrue(os.path.exists(pkgs_fname))
     self.assertEqual(open(pkgs_fname, 'r').read(), '<packages/>\n')
     apiurl_fname = os.path.join(tmpdir, '.osc', '_apiurl')
     self.assertTrue(os.path.exists(apiurl_fname))
     self.assertEqual(open(apiurl_fname, 'r').read(),
                      'https://api.opensuse.org\n')
     data_dir = os.path.join(tmpdir, '.osc', 'data')
     self.assertTrue(os.path.exists(data_dir))
     self.assertEqual(prj.name, 'openSUSE:Tools')
     self.assertEqual(prj.apiurl, 'https://api.opensuse.org')
     self.assertTrue(len(prj.packages()) == 0)
     self.assertTrue(len(prj.notifier.listener) == 0)
示例#12
0
 def test1(self):
     """init a project dir"""
     tmpdir = mkdtemp(dir=self._tmp_dir)
     prj = Project.init(tmpdir, 'openSUSE:Tools',
                        'https://api.opensuse.org')
     prj_fname = os.path.join(tmpdir, '.osc', '_project')
     self.assertTrue(os.path.exists(prj_fname))
     self.assertEqual(open(prj_fname, 'r').read(), 'openSUSE:Tools\n')
     pkgs_fname = os.path.join(tmpdir, '.osc', '_packages')
     self.assertTrue(os.path.exists(pkgs_fname))
     self.assertEqual(open(pkgs_fname, 'r').read(), '<packages/>\n')
     apiurl_fname = os.path.join(tmpdir, '.osc', '_apiurl')
     self.assertTrue(os.path.exists(apiurl_fname))
     self.assertEqual(open(apiurl_fname, 'r').read(),
                      'https://api.opensuse.org\n')
     data_dir = os.path.join(tmpdir, '.osc', 'data')
     self.assertTrue(os.path.exists(data_dir))
     self.assertEqual(prj.name, 'openSUSE:Tools')
     self.assertEqual(prj.apiurl, 'https://api.opensuse.org')
     self.assertTrue(len(prj.packages()) == 0)
     self.assertTrue(len(prj.notifier.listener) == 0)
示例#13
0
 def test1_2(self):
     """init (pass additional arguments to the Project's __init__ method)"""
     # nearly identical to test1
     tmpdir = mkdtemp(dir=self._tmp_dir)
     prj = Project.init(tmpdir, 'openSUSE:Tools',
                        'https://api.opensuse.org',
                        transaction_listener=[None])
     prj_fname = os.path.join(tmpdir, '.osc', '_project')
     self.assertTrue(os.path.exists(prj_fname))
     self.assertEqual(open(prj_fname, 'r').read(), 'openSUSE:Tools\n')
     pkgs_fname = os.path.join(tmpdir, '.osc', '_packages')
     self.assertTrue(os.path.exists(pkgs_fname))
     self.assertEqual(open(pkgs_fname, 'r').read(), '<packages/>\n')
     apiurl_fname = os.path.join(tmpdir, '.osc', '_apiurl')
     self.assertTrue(os.path.exists(apiurl_fname))
     self.assertEqual(open(apiurl_fname, 'r').read(),
                      'https://api.opensuse.org\n')
     data_dir = os.path.join(tmpdir, '.osc', 'data')
     self.assertTrue(os.path.exists(data_dir))
     self.assertEqual(prj.name, 'openSUSE:Tools')
     self.assertEqual(prj.apiurl, 'https://api.opensuse.org')
     self.assertTrue(len(prj.packages()) == 0)
     self.assertTrue(len(prj.notifier.listener) == 1)
示例#14
0
 def test1_2(self):
     """init (pass additional arguments to the Project's __init__ method)"""
     # nearly identical to test1
     tmpdir = mkdtemp(dir=self._tmp_dir)
     prj = Project.init(tmpdir, 'openSUSE:Tools',
                        'https://api.opensuse.org',
                        transaction_listener=[None])
     prj_fname = os.path.join(tmpdir, '.osc', '_project')
     self.assertTrue(os.path.exists(prj_fname))
     self.assertEqual(open(prj_fname, 'r').read(), 'openSUSE:Tools\n')
     pkgs_fname = os.path.join(tmpdir, '.osc', '_packages')
     self.assertTrue(os.path.exists(pkgs_fname))
     self.assertEqual(open(pkgs_fname, 'r').read(), '<packages/>\n')
     apiurl_fname = os.path.join(tmpdir, '.osc', '_apiurl')
     self.assertTrue(os.path.exists(apiurl_fname))
     self.assertEqual(open(apiurl_fname, 'r').read(),
                      'https://api.opensuse.org\n')
     data_dir = os.path.join(tmpdir, '.osc', 'data')
     self.assertTrue(os.path.exists(data_dir))
     self.assertEqual(prj.name, 'openSUSE:Tools')
     self.assertEqual(prj.apiurl, 'https://api.opensuse.org')
     self.assertTrue(len(prj.packages()) == 0)
     self.assertTrue(len(prj.notifier.listener) == 1)
示例#15
0
文件: test_io.py 项目: pombreda/osc2
 def test_mkdtemp6(self):
     """test context manager"""
     with mkdtemp(dir=self._tmpdir) as tmpdir:
         self.assertTrue(os.path.isdir(tmpdir))
     self.assertFalse(os.path.isdir(tmpdir))
示例#16
0
文件: test_io.py 项目: pombreda/osc2
 def test_mkdtemp2(self):
     """simple mkdtemp (remove with rmdir)"""
     tmpdir = mkdtemp(dir=self._tmpdir)
     self.assertTrue(os.path.isdir(tmpdir))
     tmpdir.rmdir()
     self.assertFalse(os.path.isdir(tmpdir))
示例#17
0
文件: test_io.py 项目: pombreda/osc2
 def test_mkdtemp1(self):
     """simple mkdtemp test"""
     tmpdir = mkdtemp(dir=self._tmpdir)
     self.assertTrue(os.path.isdir(tmpdir))
     tmpdir.rmtree()
     self.assertFalse(os.path.isdir(tmpdir))
示例#18
0
 def test_mkdtemp6(self):
     """test context manager"""
     with mkdtemp(dir=self._tmpdir) as tmpdir:
         self.assertTrue(os.path.isdir(tmpdir))
     self.assertFalse(os.path.isdir(tmpdir))
示例#19
0
 def test_mkdtemp1(self):
     """simple mkdtemp test"""
     tmpdir = mkdtemp(dir=self._tmpdir)
     self.assertTrue(os.path.isdir(tmpdir))
     tmpdir.rmtree()
     self.assertFalse(os.path.isdir(tmpdir))
示例#20
0
 def test_mkdtemp2(self):
     """simple mkdtemp (remove with rmdir)"""
     tmpdir = mkdtemp(dir=self._tmpdir)
     self.assertTrue(os.path.isdir(tmpdir))
     tmpdir.rmdir()
     self.assertFalse(os.path.isdir(tmpdir))