How to use make_fs method in tempest

Best Python code snippet using tempest_python

test_fs.py

Source:test_fs.py Github

copy

Full Screen

2import pytest3from pytest_test_utils import TmpDir4from scmrepo.git import Git5@pytest.fixture(name="make_fs")6def fixture_make_fs(scm: Git, git: Git):7 def _make_fs(rev=None):8 from scmrepo.fs import GitFileSystem9 from scmrepo.git.objects import GitTrie10 # NOTE: not all git backends have `resolve_rev` implemented,11 # so we are using whichever works.12 resolved = scm.resolve_rev(rev or "HEAD")13 tree = git.get_tree_obj(rev=resolved)14 trie = GitTrie(tree, resolved)15 return GitFileSystem(trie=trie)16 return _make_fs17def test_open(tmp_dir: TmpDir, scm: Git, make_fs):18 files = tmp_dir.gen(19 {"foo": "foo", "тест": "проверка", "data": {"lorem": "ipsum"}}20 )21 scm.add_commit(files, message="add")22 fs = make_fs()23 with fs.open("foo", mode="r", encoding="utf-8") as fobj:24 assert fobj.read() == "foo"25 with fs.open("тест", mode="r", encoding="utf-8") as fobj:26 assert fobj.read() == "проверка"27 with pytest.raises(IOError):28 fs.open("not-existing-file")29 with pytest.raises(IOError):30 fs.open("data")31def test_exists(tmp_dir: TmpDir, scm: Git, make_fs):32 scm.commit("init")33 files = tmp_dir.gen(34 {"foo": "foo", "тест": "проверка", "data": {"lorem": "ipsum"}}35 )36 fs = make_fs()37 assert fs.exists("/")38 assert fs.exists(".")39 assert not fs.exists("foo")40 assert not fs.exists("тест")41 assert not fs.exists("data")42 assert not fs.exists("data/lorem")43 scm.add_commit(files, message="add")44 fs = make_fs()45 assert fs.exists("/")46 assert fs.exists(".")47 assert fs.exists("foo")48 assert fs.exists("тест")49 assert fs.exists("data")50 assert fs.exists("data/lorem")51 assert not fs.exists("non-existing-file")52def test_isdir(tmp_dir: TmpDir, scm: Git, make_fs):53 tmp_dir.gen({"foo": "foo", "тест": "проверка", "data": {"lorem": "ipsum"}})54 scm.add_commit(["foo", "data"], message="add")55 fs = make_fs()56 assert fs.isdir("/")57 assert fs.isdir(".")58 assert fs.isdir("data")59 assert not fs.isdir("foo")60 assert not fs.isdir("non-existing-file")61def test_isfile(tmp_dir: TmpDir, scm: Git, make_fs):62 tmp_dir.gen({"foo": "foo", "тест": "проверка", "data": {"lorem": "ipsum"}})63 scm.add_commit(["foo", "data"], message="add")64 fs = make_fs()65 assert not fs.isfile("/")66 assert not fs.isfile(".")67 assert fs.isfile("foo")68 assert not fs.isfile("data")69 assert not fs.isfile("not-existing-file")70def test_walk(tmp_dir: TmpDir, scm: Git, make_fs):71 tmp_dir.gen(72 {73 "foo": "foo",74 "тест": "проверка",75 "data": {"lorem": "ipsum", "subdir": {"sub": "sub"}},76 }77 )78 scm.add_commit("data/subdir", message="add")79 fs = make_fs()80 def convert_to_sets(walk_results):81 return [82 (root, set(dirs), set(nondirs))83 for root, dirs, nondirs in walk_results84 ]85 assert convert_to_sets(fs.walk("/")) == convert_to_sets(86 [87 ("/", ["data"], []),88 ("/data", ["subdir"], []),89 (90 "/data/subdir",91 [],92 ["sub"],93 ),94 ]95 )96 assert convert_to_sets(fs.walk("data/subdir")) == convert_to_sets(97 [98 (99 "data/subdir",100 [],101 ["sub"],102 )103 ]104 )105def test_walk_with_submodules(106 scm: Git,107 remote_git_dir: TmpDir,108 make_fs,109):110 remote_git = Git(remote_git_dir)111 remote_git_dir.gen({"foo": "foo", "bar": "bar", "dir": {"data": "data"}})112 remote_git.add_commit(["foo", "bar", "dir"], message="add dir and files")113 scm.gitpython.repo.create_submodule(114 "submodule", "submodule", url=os.fspath(remote_git_dir)115 )116 scm.commit("added submodule")117 files = []118 dirs = []119 fs = make_fs()120 for _, dnames, fnames in fs.walk(""):121 dirs.extend(dnames)122 files.extend(fnames)123 # currently we don't walk through submodules124 assert not dirs125 assert set(files) == {".gitmodules", "submodule"}126def test_ls(tmp_dir: TmpDir, scm: Git, make_fs):127 files = tmp_dir.gen(128 {129 "foo": "foo",130 "тест": "проверка",131 "data": {"lorem": "ipsum", "subdir": {"sub": "sub"}},132 }133 )134 scm.add_commit(files, message="add")135 fs = make_fs()136 assert fs.ls("/", detail=False) == ["/data", "/foo", "/тест"]137 assert fs.ls("/") == [138 {139 "mode": 16384,140 "name": "/data",141 "sha": "f5d6ac1955c85410b71bb6e35e4c57c54e2ad524",142 "size": 66,143 "type": "directory",144 },145 {146 "mode": 33188,147 "name": "/foo",148 "sha": "19102815663d23f8b75a47e7a01965dcdc96468c",149 "size": 3,...

Full Screen

Full Screen

test_githubfs.py

Source:test_githubfs.py Github

copy

Full Screen

...11# from fs.opener import open_fs12from fs.github import GithubFS13from six import text_type14class TestGithubFS(unittest.TestCase):15 def make_fs(self):16 # Return an instance of your FS object here17 pw = None18 if os.path.isfile('c:\\temp\\p.txt'):19 with open('c:\\temp\\p.txt','r') as pwf:20 pw = pwf.read()21 githubfs = GithubFS('merlink01','fs.github',pw)22 return githubfs23 @classmethod24 def destroy_fs(self, fs):25 """26 Destroy a FS object.27 :param fs: A FS instance previously opened by28 `~fs.test.FSTestCases.make_fs`.29 """30 fs.close()31 def setUp(self):32 self.fs = self.make_fs()33 def tearDown(self):34 self.destroy_fs(self.fs)35 del self.fs36 def test_simple(self):37 if self.fs.account.get_rate_limit().core.remaining < 10:38 print('Ratelimit reached, disable Testing')39 return40 print(self.fs)41 filelist = self.fs.listdir('/')42 assert 'README.md' in filelist43 assert 'fs' in filelist44 assert self.fs.isdir('/') == True45 assert self.fs.isdir('/LICENSE') == False46 assert self.fs.isdir('/fs') == True...

Full Screen

Full Screen

context.py

Source:context.py Github

copy

Full Screen

...15 """16 if server_setup.DEPLOYMENT_MODE == DeploymentMode.Server:17 if make_fs is None:18 make_fs = lambda: None # noqa: E73119 return SSHDataAccess(make_fs())20 return LocalDataAccess()21 @staticmethod22 def get_launcher(scenario):23 """Return instance for interaction with simulation engine24 :param powersimdata.scenario.scenario.Scenario scenario: a scenario object25 :return: (:class:`powersimdata.data_access.launcher.Launcher`) -- a launcher instance26 """27 mode = server_setup.DEPLOYMENT_MODE28 if mode == DeploymentMode.Server:29 return SSHLauncher(scenario)30 elif mode == DeploymentMode.Container:31 return HttpLauncher(scenario)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful