コード例 #1
0
    def do_test(dirname):
        from codecs import open as real_open

        envdir = os.path.join(dirname, spec.name)

        manager = DefaultCondaManager(frontend=NullFrontend())

        counts = dict(calls=0)

        def mock_open(*args, **kwargs):
            counts['calls'] += 1
            if counts['calls'] == 1:
                raise IOError("did not open")
            else:
                return real_open(*args, **kwargs)

        monkeypatch.setattr('codecs.open', mock_open)

        # this should NOT throw but also should not write the
        # timestamp file (we ignore errors)
        filename = manager._timestamp_file(envdir, spec)
        assert filename.startswith(envdir)
        assert not os.path.exists(filename)
        manager._write_timestamp_file(envdir, spec)
        assert not os.path.exists(filename)
        # the second time we really wsrite it (this is to prove we
        # are looking at the right filename)
        manager._write_timestamp_file(envdir, spec)
        assert os.path.exists(filename)

        # check on the file contents
        with real_open(filename, 'r', encoding='utf-8') as f:
            content = json.loads(f.read())
            assert dict(anaconda_project_version=version) == content
コード例 #2
0
    def do_test(dirname):
        from codecs import open as real_open

        envdir = os.path.join(dirname, spec.name)

        manager = DefaultCondaManager()

        counts = dict(calls=0)

        def mock_open(*args, **kwargs):
            counts['calls'] += 1
            if counts['calls'] == 1:
                raise IOError("did not open")
            else:
                return real_open(*args, **kwargs)

        monkeypatch.setattr('codecs.open', mock_open)

        # this should NOT throw but also should not write the
        # timestamp file (we ignore errors)
        filename = manager._timestamp_file(envdir, spec)
        assert filename.startswith(envdir)
        assert not os.path.exists(filename)
        manager._write_timestamp_file(envdir, spec)
        assert not os.path.exists(filename)
        # the second time we really write it (this is to prove we
        # are looking at the right filename)
        manager._write_timestamp_file(envdir, spec)
        assert os.path.exists(filename)

        # check on the file contents
        with real_open(filename, 'r', encoding='utf-8') as f:
            content = json.loads(f.read())
            assert dict(conda_kapsel_version=version) == content
コード例 #3
0
 def mock_codecs_open(*args, **kwargs):
     if args[0].endswith(".projectignore"):
         raise IOError("NOPE")
     else:
         return real_open(*args, **kwargs)
コード例 #4
0
 def mock_open(*args, **kwargs):
     counts['calls'] += 1
     if counts['calls'] == 1:
         raise IOError("did not open")
     else:
         return real_open(*args, **kwargs)
コード例 #5
0
 def mock_open(*args, **kwargs):
     if is_readonly['readonly']:
         raise IOError("did not open")
     return real_open(*args, **kwargs)
コード例 #6
0
ファイル: test_bundler.py プロジェクト: conda/kapsel
 def mock_codecs_open(*args, **kwargs):
     if args[0].endswith(".kapselignore"):
         raise IOError("NOPE")
     else:
         return real_open(*args, **kwargs)
コード例 #7
0
 def mock_open(*args, **kwargs):
     counts['calls'] += 1
     if counts['calls'] == 1:
         raise IOError("did not open")
     else:
         return real_open(*args, **kwargs)