How to use create_config_file method in localstack

Best Python code snippet using localstack_python

test_config_integration.py

Source:test_config_integration.py Github

copy

Full Screen

...218 Feature,219 projects=[self.project],220 feature_id=Feature.ALLOW_V2_CONFIG_FILE,221 )222 def create_config_file(self, tmpdir, config):223 base_path = apply_fs(tmpdir, {224 'readthedocs.yml': '',225 })226 config.setdefault('version', 2)227 config_file = path.join(str(base_path), 'readthedocs.yml')228 yaml.safe_dump(config, open(config_file, 'w'))229 return base_path230 def get_update_docs_task(self):231 build_env = LocalBuildEnvironment(232 self.project, self.version, record=False233 )234 update_docs = tasks.UpdateDocsTaskStep(235 build_env=build_env,236 config=load_yaml_config(self.version),237 project=self.project,238 version=self.version,239 )240 return update_docs241 def test_using_v2(self, checkout_path, tmpdir):242 checkout_path.return_value = str(tmpdir)243 self.create_config_file(tmpdir, {})244 update_docs = self.get_update_docs_task()245 assert update_docs.config.version == '2'246 def test_report_using_invalid_version(self, checkout_path, tmpdir):247 checkout_path.return_value = str(tmpdir)248 self.create_config_file(tmpdir, {'version': 12})249 with pytest.raises(InvalidConfig) as exinfo:250 self.get_update_docs_task()251 assert exinfo.value.key == 'version'252 @pytest.mark.parametrize('config', [{}, {'formats': []}])253 @patch('readthedocs.projects.models.Project.repo_nonblockinglock', new=MagicMock())254 @patch('readthedocs.doc_builder.backends.sphinx.HtmlBuilder.build')255 @patch('readthedocs.doc_builder.backends.sphinx.HtmlBuilder.append_conf')256 def test_build_formats_default_empty(257 self, append_conf, html_build, checkout_path, config, tmpdir):258 """259 The default value for formats is [], which means no extra260 formats are build.261 """262 checkout_path.return_value = str(tmpdir)263 self.create_config_file(tmpdir, config)264 update_docs = self.get_update_docs_task()265 python_env = Virtualenv(266 version=self.version,267 build_env=update_docs.build_env,268 config=update_docs.config269 )270 update_docs.python_env = python_env271 outcomes = update_docs.build_docs()272 # No extra formats were triggered273 assert outcomes['html']274 assert not outcomes['localmedia']275 assert not outcomes['pdf']276 assert not outcomes['epub']277 @patch('readthedocs.projects.models.Project.repo_nonblockinglock', new=MagicMock())278 @patch('readthedocs.projects.tasks.UpdateDocsTaskStep.build_docs_class')279 @patch('readthedocs.doc_builder.backends.sphinx.HtmlBuilder.build')280 @patch('readthedocs.doc_builder.backends.sphinx.HtmlBuilder.append_conf')281 def test_build_formats_only_pdf(282 self, append_conf, html_build, build_docs_class,283 checkout_path, tmpdir):284 """285 Only the pdf format is build.286 """287 checkout_path.return_value = str(tmpdir)288 self.create_config_file(tmpdir, {'formats': ['pdf']})289 update_docs = self.get_update_docs_task()290 python_env = Virtualenv(291 version=self.version,292 build_env=update_docs.build_env,293 config=update_docs.config294 )295 update_docs.python_env = python_env296 outcomes = update_docs.build_docs()297 # Only pdf extra format was triggered298 assert outcomes['html']299 build_docs_class.assert_called_with('sphinx_pdf')300 assert outcomes['pdf']301 assert not outcomes['localmedia']302 assert not outcomes['epub']303 @patch('readthedocs.projects.tasks.UpdateDocsTaskStep.update_documentation_type', new=MagicMock())304 @patch('readthedocs.projects.tasks.UpdateDocsTaskStep.setup_python_environment', new=MagicMock())305 @patch('readthedocs.projects.tasks.UpdateDocsTaskStep.build_docs', new=MagicMock())306 @patch('readthedocs.doc_builder.environments.BuildEnvironment.failed', new_callable=PropertyMock)307 def test_conda_environment(self, build_failed, checkout_path, tmpdir):308 build_failed.return_value = False309 checkout_path.return_value = str(tmpdir)310 conda_file = 'environmemt.yml'311 apply_fs(tmpdir, {conda_file: ''})312 base_path = self.create_config_file(313 tmpdir,314 {315 'conda': {'environment': conda_file}316 }317 )318 update_docs = self.get_update_docs_task()319 update_docs.run_build(docker=False, record=False)320 conda_file = path.join(str(base_path), conda_file)321 assert update_docs.config.conda.environment == conda_file322 assert isinstance(update_docs.python_env, Conda)323 def test_default_build_image(self, checkout_path, tmpdir):324 checkout_path.return_value = str(tmpdir)325 build_image = 'readthedocs/build:latest'326 self.create_config_file(tmpdir, {})327 update_docs = self.get_update_docs_task()328 assert update_docs.config.build.image == build_image329 def test_build_image(self, checkout_path, tmpdir):330 checkout_path.return_value = str(tmpdir)331 build_image = 'readthedocs/build:stable'332 self.create_config_file(333 tmpdir,334 {'build': {'image': 'stable'}},335 )336 update_docs = self.get_update_docs_task()337 assert update_docs.config.build.image == build_image338 def test_custom_build_image(self, checkout_path, tmpdir):339 checkout_path.return_value = str(tmpdir)340 build_image = 'readthedocs/build:3.0'341 self.project.container_image = build_image342 self.project.save()343 self.create_config_file(tmpdir, {})344 update_docs = self.get_update_docs_task()345 assert update_docs.config.build.image == build_image346 def test_python_version(self, checkout_path, tmpdir):347 checkout_path.return_value = str(tmpdir)348 self.create_config_file(tmpdir, {})349 # The default version is always 3350 self.project.python_interpreter = 'python2'351 self.project.save()352 config = self.get_update_docs_task().config353 assert config.python.version == 3354 assert config.python_full_version == 3.6355 @patch('readthedocs.doc_builder.environments.BuildEnvironment.run')356 def test_python_requirements(self, run, checkout_path, tmpdir):357 checkout_path.return_value = str(tmpdir)358 requirements_file = 'requirements.txt'359 apply_fs(tmpdir, {requirements_file: ''})360 base_path = self.create_config_file(361 tmpdir,362 {363 'python': {'requirements': requirements_file}364 }365 )366 update_docs = self.get_update_docs_task()367 config = update_docs.config368 python_env = Virtualenv(369 version=self.version,370 build_env=update_docs.build_env,371 config=config372 )373 update_docs.python_env = python_env374 update_docs.python_env.install_user_requirements()375 args, kwargs = run.call_args376 requirements_file = path.join(str(base_path), requirements_file)377 assert config.python.requirements == requirements_file378 assert requirements_file in args379 @patch('readthedocs.doc_builder.environments.BuildEnvironment.run')380 def test_python_requirements_empty(self, run, checkout_path, tmpdir):381 checkout_path.return_value = str(tmpdir)382 self.create_config_file(383 tmpdir,384 {385 'python': {'requirements': ''}386 }387 )388 update_docs = self.get_update_docs_task()389 config = update_docs.config390 python_env = Virtualenv(391 version=self.version,392 build_env=update_docs.build_env,393 config=config394 )395 update_docs.python_env = python_env396 update_docs.python_env.install_user_requirements()397 assert config.python.requirements == ''398 assert not run.called399 @patch('readthedocs.doc_builder.environments.BuildEnvironment.run')400 def test_python_install_setup(self, run, checkout_path, tmpdir):401 checkout_path.return_value = str(tmpdir)402 self.create_config_file(403 tmpdir,404 {405 'python': {'install': 'setup.py'}406 }407 )408 update_docs = self.get_update_docs_task()409 config = update_docs.config410 python_env = Virtualenv(411 version=self.version,412 build_env=update_docs.build_env,413 config=config414 )415 update_docs.python_env = python_env416 update_docs.python_env.install_package()417 args, kwargs = run.call_args418 assert 'setup.py' in args419 assert 'install' in args420 assert config.python.install_with_setup421 assert not config.python.install_with_pip422 @patch('readthedocs.doc_builder.environments.BuildEnvironment.run')423 def test_python_install_pip(self, run, checkout_path, tmpdir):424 checkout_path.return_value = str(tmpdir)425 self.create_config_file(426 tmpdir,427 {428 'python': {'install': 'pip'}429 }430 )431 update_docs = self.get_update_docs_task()432 config = update_docs.config433 python_env = Virtualenv(434 version=self.version,435 build_env=update_docs.build_env,436 config=config437 )438 update_docs.python_env = python_env439 update_docs.python_env.install_package()440 args, kwargs = run.call_args441 assert 'setup.py' not in args442 assert 'install' in args443 assert config.python.install_with_pip444 assert not config.python.install_with_setup445 def test_python_install_project(self, checkout_path, tmpdir):446 checkout_path.return_value = str(tmpdir)447 self.create_config_file(tmpdir, {})448 self.project.install_project = True449 self.project.save()450 config = self.get_update_docs_task().config451 assert config.python.install_with_setup452 assert not config.python.install_with_pip453 @patch('readthedocs.doc_builder.environments.BuildEnvironment.run')454 def test_python_extra_requirements(self, run, checkout_path, tmpdir):455 checkout_path.return_value = str(tmpdir)456 self.create_config_file(457 tmpdir,458 {459 'python': {460 'install': 'pip',461 'extra_requirements': ['docs'],462 }463 }464 )465 update_docs = self.get_update_docs_task()466 config = update_docs.config467 python_env = Virtualenv(468 version=self.version,469 build_env=update_docs.build_env,470 config=config471 )472 update_docs.python_env = python_env473 update_docs.python_env.install_package()474 args, kwargs = run.call_args475 assert 'setup.py' not in args476 assert 'install' in args477 assert '.[docs]' in args478 assert config.python.install_with_pip479 assert not config.python.install_with_setup480 @patch('readthedocs.doc_builder.environments.BuildEnvironment.run')481 def test_system_packages(self, run, checkout_path, tmpdir):482 checkout_path.return_value = str(tmpdir)483 self.create_config_file(484 tmpdir,485 {486 'python': {487 'system_packages': True,488 }489 }490 )491 update_docs = self.get_update_docs_task()492 config = update_docs.config493 python_env = Virtualenv(494 version=self.version,495 build_env=update_docs.build_env,496 config=config497 )498 update_docs.python_env = python_env499 update_docs.python_env.setup_base()500 args, kwargs = run.call_args501 assert '--system-site-packages' in args502 assert config.python.use_system_site_packages503 @pytest.mark.parametrize('value,result',504 [('html', 'sphinx'),505 ('htmldir', 'sphinx_htmldir'),506 ('singlehtml', 'sphinx_singlehtml')])507 @patch('readthedocs.projects.tasks.get_builder_class')508 def test_sphinx_builder(509 self, get_builder_class, checkout_path, value, result, tmpdir):510 checkout_path.return_value = str(tmpdir)511 self.create_config_file(tmpdir, {'sphinx': {'builder': value}})512 self.project.documentation_type = 'mkdocs'513 self.project.save()514 update_docs = self.get_update_docs_task()515 update_docs.build_docs_html()516 get_builder_class.assert_called_with(result)517 @patch('readthedocs.projects.tasks.get_builder_class')518 def test_sphinx_builder_default(519 self, get_builder_class, checkout_path, tmpdir):520 checkout_path.return_value = str(tmpdir)521 self.create_config_file(tmpdir, {})522 self.project.documentation_type = 'mkdocs'523 self.project.save()524 update_docs = self.get_update_docs_task()525 update_docs.build_docs_html()526 get_builder_class.assert_called_with('sphinx')527 @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.move')528 @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.append_conf')529 @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.run')530 def test_sphinx_configuration_default(531 self, run, append_conf, move, checkout_path, tmpdir):532 """Should be default to find a conf.py file."""533 checkout_path.return_value = str(tmpdir)534 apply_fs(tmpdir, {'conf.py': ''})535 self.create_config_file(tmpdir, {})536 self.project.conf_py_file = ''537 self.project.save()538 update_docs = self.get_update_docs_task()539 config = update_docs.config540 python_env = Virtualenv(541 version=self.version,542 build_env=update_docs.build_env,543 config=config544 )545 update_docs.python_env = python_env546 update_docs.build_docs_html()547 args, kwargs = run.call_args548 assert kwargs['cwd'] == str(tmpdir)549 append_conf.assert_called_once()550 move.assert_called_once()551 @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.move')552 @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.append_conf')553 @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.run')554 def test_sphinx_configuration_default(555 self, run, append_conf, move, checkout_path, tmpdir):556 """Should be default to find a conf.py file."""557 checkout_path.return_value = str(tmpdir)558 apply_fs(tmpdir, {'conf.py': ''})559 self.create_config_file(tmpdir, {})560 self.project.conf_py_file = ''561 self.project.save()562 update_docs = self.get_update_docs_task()563 config = update_docs.config564 python_env = Virtualenv(565 version=self.version,566 build_env=update_docs.build_env,567 config=config568 )569 update_docs.python_env = python_env570 update_docs.build_docs_html()571 args, kwargs = run.call_args572 assert kwargs['cwd'] == str(tmpdir)573 append_conf.assert_called_once()574 move.assert_called_once()575 @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.move')576 @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.append_conf')577 @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.run')578 def test_sphinx_configuration(579 self, run, append_conf, move, checkout_path, tmpdir):580 checkout_path.return_value = str(tmpdir)581 apply_fs(tmpdir, {582 'conf.py': '',583 'docx': {584 'conf.py': '',585 },586 })587 self.create_config_file(588 tmpdir,589 {590 'sphinx': {591 'configuration': 'docx/conf.py',592 },593 }594 )595 update_docs = self.get_update_docs_task()596 config = update_docs.config597 python_env = Virtualenv(598 version=self.version,599 build_env=update_docs.build_env,600 config=config601 )602 update_docs.python_env = python_env603 update_docs.build_docs_html()604 args, kwargs = run.call_args605 assert kwargs['cwd'] == path.join(str(tmpdir), 'docx')606 append_conf.assert_called_once()607 move.assert_called_once()608 @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.move')609 @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.append_conf')610 @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.run')611 def test_sphinx_fail_on_warning(612 self, run, append_conf, move, checkout_path, tmpdir):613 checkout_path.return_value = str(tmpdir)614 apply_fs(tmpdir, {615 'docx': {616 'conf.py': '',617 },618 })619 self.create_config_file(620 tmpdir,621 {622 'sphinx': {623 'configuration': 'docx/conf.py',624 'fail_on_warning': True,625 },626 }627 )628 update_docs = self.get_update_docs_task()629 config = update_docs.config630 python_env = Virtualenv(631 version=self.version,632 build_env=update_docs.build_env,633 config=config634 )635 update_docs.python_env = python_env636 update_docs.build_docs_html()637 args, kwargs = run.call_args638 assert '-W' in args639 append_conf.assert_called_once()640 move.assert_called_once()641 @pytest.mark.skip642 @patch('readthedocs.doc_builder.backends.mkdocs.BaseMkdocs.move')643 @patch('readthedocs.doc_builder.backends.mkdocs.BaseMkdocs.append_conf')644 @patch('readthedocs.doc_builder.backends.mkdocs.BaseMkdocs.run')645 def test_mkdocs_configuration(646 self, run, append_conf, move, checkout_path, tmpdir):647 checkout_path.return_value = str(tmpdir)648 apply_fs(tmpdir, {649 'mkdocs.yml': '',650 'docx': {651 'mkdocs.yml': '',652 },653 })654 self.create_config_file(655 tmpdir,656 {657 'mkdocs': {658 'configuration': 'docx/mkdocs.yml',659 },660 }661 )662 update_docs = self.get_update_docs_task()663 config = update_docs.config664 python_env = Virtualenv(665 version=self.version,666 build_env=update_docs.build_env,667 config=config668 )669 update_docs.python_env = python_env670 update_docs.build_docs_html()671 args, kwargs = run.call_args672 assert '--config-file' in args673 assert path.join(str(tmpdir), 'docx/mkdocs.yml') in args674 append_conf.assert_called_once()675 move.assert_called_once()676 @pytest.mark.skip677 @patch('readthedocs.doc_builder.backends.mkdocs.BaseMkdocs.move')678 @patch('readthedocs.doc_builder.backends.mkdocs.BaseMkdocs.append_conf')679 @patch('readthedocs.doc_builder.backends.mkdocs.BaseMkdocs.run')680 def test_mkdocs_fail_on_warning(681 self, run, append_conf, move, checkout_path, tmpdir):682 checkout_path.return_value = str(tmpdir)683 apply_fs(tmpdir, {684 'docx': {685 'mkdocs.yml': '',686 },687 })688 self.create_config_file(689 tmpdir,690 {691 'mkdocs': {692 'configuration': 'docx/mkdocs.yml',693 'fail_on_warning': True,694 },695 }696 )697 update_docs = self.get_update_docs_task()698 config = update_docs.config699 python_env = Virtualenv(700 version=self.version,701 build_env=update_docs.build_env,702 config=config...

Full Screen

Full Screen

config_file_backing_store_tests.py

Source:config_file_backing_store_tests.py Github

copy

Full Screen

...14 self.tempdir = tempfile.mkdtemp()15 self.tempfile = os.path.join(self.tempdir, "test.ini")16 def tearDown(self):17 shutil.rmtree(self.tempdir)18 def create_config_file(self, path, sections_dict):19 # This will write a ConfigFile at `path` with the sections/keys/values20 # pulled from keys/values of the nested section dicitionary21 #22 # A dictionary like this:23 # {24 # "Section Name": {25 # "key":value,26 # "key":value,27 # ...28 # },29 # "Section Name 2": {30 # "key2":value,31 # "key2":value,32 # ...33 # },34 # ...35 # }36 #37 # Will produce an output like this38 # [Section Name]39 # key=value40 # key=value41 #42 # [Section Name 2]43 # key2=value44 # key2=value45 f = open(path, "w")46 for section_name in sections_dict.keys():47 f.write("[%s]\n" % section_name)48 keyvalues = sections_dict[section_name]49 for key in keyvalues.keys():50 value = keyvalues[key]51 f.write("%s=%s\n" % (key, value))52 f.write("\n")53 f.close()54 def file_contents(self, path):55 f = open(path, "r")56 contents = f.read()57 f.close()58 return contents59 def test_empty_file(self):60 self.create_config_file(self.tempfile, {})61 cfbs = ConfigFileBackingStore(self.tempfile)62 self.assertEquals(cfbs.identifiers(), [])63 def test_identifiers(self):64 self.create_config_file(self.tempfile, {65 "Iron Man": {},66 "Whiplash": {},67 })68 cfbs = ConfigFileBackingStore(self.tempfile)69 self.assertEquals(cfbs.identifiers(), ["Iron Man", "Whiplash"])70 def test_added_identifiers_show_up_in_subsequent_calls(self):71 self.create_config_file(self.tempfile, {})72 cfbs = ConfigFileBackingStore(self.tempfile)73 cfbs.add_identifier("Iron Man")74 self.assertIn("Iron Man", cfbs.identifiers())75 def test_removed_identifiers_dont_show_up_in_subsequent_calls(self):76 self.create_config_file(self.tempfile, {"Iron Man": {}})77 cfbs = ConfigFileBackingStore(self.tempfile)78 cfbs.remove_identifier("Iron Man")79 self.assertNotIn("Iron Man", cfbs.identifiers())80 def test_add_identifier_raises_valueerror_when_identifier_exists(self):81 self.create_config_file(self.tempfile, {"Iron Man": {}})82 cfbs = ConfigFileBackingStore(self.tempfile)83 with self.assertRaises(ValueError):84 cfbs.add_identifier("Iron Man")85 def test_remove_identifier_does_nothing_when_identifer_dne(self):86 self.create_config_file(self.tempfile, {})87 cfbs = ConfigFileBackingStore(self.tempfile)88 self.assertNotIn("Iron Man", cfbs.identifiers())89 cfbs.remove_identifier("Iron Man")90 self.assertNotIn("Iron Man", cfbs.identifiers())91 def test_keys_raises_valueerror_when_section_dne(self):92 self.create_config_file(self.tempfile, {})93 cfbs = ConfigFileBackingStore(self.tempfile)94 with self.assertRaises(ValueError):95 cfbs.keys("Iron Man")96 def test_get(self):97 self.create_config_file(self.tempfile, {"Iron Man": {98 "identity": "Tony Stark",99 "alignment": "good",100 }})101 cfbs = ConfigFileBackingStore(self.tempfile)102 self.assertEqual(cfbs.get("Iron Man", "identity", ""), "Tony Stark")103 def test_get_returns_default_when_key_dne(self):104 self.create_config_file(self.tempfile, {"Iron Man": {}})105 cfbs = ConfigFileBackingStore(self.tempfile)106 self.assertEqual(cfbs.get("Iron Man", "identity", ""), "")107 def test_get_returns_default_when_section_dne(self):108 self.create_config_file(self.tempfile, {"Iron Man": {}})109 cfbs = ConfigFileBackingStore(self.tempfile)110 self.assertEqual(cfbs.get("Superman", "identity", "Unknown"), "Unknown")111 def test_get_returns_empty_string_when_value_is_emptry_string(self):112 self.create_config_file(self.tempfile, {"Iron Man": {113 "identity": ""114 }})115 cfbs = ConfigFileBackingStore(self.tempfile)116 self.assertEqual(cfbs.get("Iron Man", "identity", "Unknown"), "")117 def test_get_keys_are_case_insensitive(self):118 self.create_config_file(self.tempfile, {"Iron Man": {119 "identity": "Tony Stark",120 "alignment": "good",121 }})122 cfbs = ConfigFileBackingStore(self.tempfile)123 self.assertEqual(cfbs.get("Iron Man", "IDENTITY", ""), "Tony Stark")124 def test_set_keys_are_case_insensitive(self):125 self.create_config_file(self.tempfile, {"Iron Man": {}})126 cfbs = ConfigFileBackingStore(self.tempfile)127 cfbs.set("Iron Man", "identity", "Tony Stark")128 self.assertEqual(cfbs.get("Iron Man", "IDENTITY", ""), "Tony Stark")129 def test_save_creates_new_file_when_path_originally_dne(self):130 self.assertFalse(os.path.isfile(self.tempfile))131 cfbs = ConfigFileBackingStore(self.tempfile)132 cfbs.add_identifier("Iron Man")133 cfbs.set("Iron Man", "identity", "Tony Stark")134 cfbs.save()135 self.assertTrue(os.path.isfile(self.tempfile))136 def test_save_modifies_contents_of_file(self):137 self.create_config_file(self.tempfile, {138 "Iron Man": {"identity": "Tony Stark"}139 })140 old_contents = self.file_contents(self.tempfile)141 cfbs = ConfigFileBackingStore(self.tempfile)142 cfbs.set("Iron Man", "alignment", "good")143 cfbs.add_identifier("Whiplash")144 cfbs.set("Whiplash", "alignment", "evil")145 cfbs.save()146 new_contents = self.file_contents(self.tempfile)147 self.assertNotIn("Whiplash", old_contents)148 self.assertIn("Whiplash", new_contents)149 self.assertNotIn("alignment", old_contents)150 self.assertIn("alignment", new_contents)151 self.assertIn("good", new_contents)152 self.assertIn("evil", new_contents)153 def test_save_raises_ioerror_when_cant_make_new_file(self):154 temppath = os.path.join(self.tempdir, "extra", "directories", "test.ini")155 cfbs = ConfigFileBackingStore(temppath)156 cfbs.add_identifier("Iron Man")157 cfbs.set("Iron Man", "identity", "Tony Stark")158 with self.assertRaises(IOError):159 cfbs.save()160 def test_config_file_backing_store_can_read_saved_file(self):161 cfbs = ConfigFileBackingStore(self.tempfile)162 cfbs.add_identifier("Iron Man")163 cfbs.set("Iron Man", "alignment", "good")164 cfbs.add_identifier("Whiplash")165 cfbs.set("Whiplash", "alignment", "evil")166 cfbs.save()167 new_cfbs = ConfigFileBackingStore(self.tempfile)168 self.assertIn("Iron Man", new_cfbs.identifiers())169 self.assertIn("Whiplash", new_cfbs.identifiers())170 self.assertEquals("good", new_cfbs.get("Iron Man", "alignment"))171 self.assertEquals("evil", new_cfbs.get("Whiplash", "alignment"))172 def test_raises_ioerror_when_permission_denied(self):173 self.create_config_file(self.tempfile, {})174 mode = os.stat(self.tempfile)[stat.ST_MODE]175 new_mode = mode & ~stat.S_IWUSR & ~stat.S_IWGRP & ~stat.S_IWOTH176 os.chmod(self.tempfile, new_mode)177 cfbs = ConfigFileBackingStore(self.tempfile)178 cfbs.add_identifier("Iron Man")179 cfbs.set("Iron Man", "identity", "Tony Stark")180 with self.assertRaises(IOError):...

Full Screen

Full Screen

test_profiles.py

Source:test_profiles.py Github

copy

Full Screen

...9 assert DEFAULT_PROFILE_NAME.isidentifier()10 def test_scan_profiles_dir(self, tmpdir):11 # Given12 base = DEFAULT_PROFILE_NAME13 create_config_file(tmpdir, f"app-{base}.yml")14 create_config_file(tmpdir, f"app-{base}1.yml")15 create_config_file(tmpdir, f"app-{base}2.yaml")16 create_config_file(tmpdir, f"app-{base}3.yml")17 create_config_file(tmpdir, f"app-{base}4.yml")18 create_config_file(tmpdir, "app-.yml")19 create_config_file(tmpdir, "some_other_file")20 expected = (21 base, f"{base}1", f"{base}3", f"{base}4"22 )23 # When24 actual = Profiles(tmpdir, 'app-', '.yml')25 # Then26 assert len(actual) == len(expected)27 assert {profile.value for profile in actual} == set(expected)28 def test_scan_empty_profiles_dir(self, tmpdir):29 with pytest.raises(RuntimeError):30 # When31 Profiles(tmpdir, 'app-', '.yml')32 # Then an error is raised because default profile is missing33 def test_scan_missing_profiles_dir(self, tmpdir):34 with pytest.raises(RuntimeError):35 # When36 Profiles(f"{tmpdir}-non-existing", 'app-', '.yml')37 # Then an error is raised because dir is inaccessible38 def test_get_by_name(self, tmpdir):39 # Given40 create_config_file(tmpdir, f"app-{DEFAULT_PROFILE_NAME}.yml")41 create_config_file(tmpdir, "app-profile1.yml")42 profiles = Profiles(tmpdir, 'app-', '.yml')43 # When44 actual = profiles.get_by_name('profile1')45 # Then46 assert actual.value == 'profile1'47 assert actual.name == 'PROFILE1'48 def test_get_config_filepath(self, tmpdir):49 # Given50 test_file_name = "app-profile_name.yml"51 create_config_file(tmpdir, f"app-{DEFAULT_PROFILE_NAME}.yml")52 create_config_file(tmpdir, test_file_name)53 profiles = Profiles(tmpdir, 'app-', '.yml')54 profile = profiles.get_by_name('profile_name')55 # When56 actual = profiles.get_config_file_path(profile)57 # Then...

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 localstack 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