How to use dependency method in pytest-bdd

Best Python code snippet using pytest-bdd_python

dependency_manager_unittest.py

Source:dependency_manager_unittest.py Github

copy

Full Screen

1# Copyright 2015 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.45# pylint: disable=unused-argument67import mock89from pyfakefs import fake_filesystem_unittest10from py_utils import cloud_storage1112import dependency_manager13from dependency_manager import exceptions141516class DependencyManagerTest(fake_filesystem_unittest.TestCase):1718 def setUp(self):19 self.lp_info012 = dependency_manager.LocalPathInfo(20 ['path0', 'path1', 'path2'])21 self.cloud_storage_info = dependency_manager.CloudStorageInfo(22 'cs_bucket', 'cs_hash', 'download_path', 'cs_remote_path')2324 self.dep_info = dependency_manager.DependencyInfo(25 'dep', 'platform', 'config_file', local_path_info=self.lp_info012,26 cloud_storage_info=self.cloud_storage_info)27 self.setUpPyfakefs()2829 def tearDown(self):30 self.tearDownPyfakefs()3132 # TODO(crbug.com/1111556): add a test that construct33 # dependency_manager.DependencyManager from a list of DependencyInfo.34 def testErrorInit(self):35 with self.assertRaises(ValueError):36 dependency_manager.DependencyManager(None)37 with self.assertRaises(ValueError):38 dependency_manager.DependencyManager('config_file?')3940 def testInitialUpdateDependencies(self):41 dep_manager = dependency_manager.DependencyManager([])4243 # Empty BaseConfig.44 dep_manager._lookup_dict = {}45 base_config_mock = mock.MagicMock(spec=dependency_manager.BaseConfig)46 base_config_mock.IterDependencyInfo.return_value = iter([])47 dep_manager._UpdateDependencies(base_config_mock)48 self.assertFalse(dep_manager._lookup_dict)4950 # One dependency/platform in a BaseConfig.51 dep_manager._lookup_dict = {}52 base_config_mock = mock.MagicMock(spec=dependency_manager.BaseConfig)53 dep_info = mock.MagicMock(spec=dependency_manager.DependencyInfo)54 dep = 'dependency'55 plat = 'platform'56 dep_info.dependency = dep57 dep_info.platform = plat58 base_config_mock.IterDependencyInfo.return_value = iter([dep_info])59 expected_lookup_dict = {dep: {plat: dep_info}}60 dep_manager._UpdateDependencies(base_config_mock)61 self.assertEqual(expected_lookup_dict, dep_manager._lookup_dict)62 self.assertFalse(dep_info.Update.called)6364 # One dependency multiple platforms in a BaseConfig.65 dep_manager._lookup_dict = {}66 base_config_mock = mock.MagicMock(spec=dependency_manager.BaseConfig)67 dep = 'dependency'68 plat1 = 'platform1'69 plat2 = 'platform2'70 dep_info1 = mock.MagicMock(spec=dependency_manager.DependencyInfo)71 dep_info1.dependency = dep72 dep_info1.platform = plat173 dep_info2 = mock.MagicMock(spec=dependency_manager.DependencyInfo)74 dep_info2.dependency = dep75 dep_info2.platform = plat276 base_config_mock.IterDependencyInfo.return_value = iter([dep_info1,77 dep_info2])78 expected_lookup_dict = {dep: {plat1: dep_info1,79 plat2: dep_info2}}80 dep_manager._UpdateDependencies(base_config_mock)81 self.assertEqual(expected_lookup_dict, dep_manager._lookup_dict)82 self.assertFalse(dep_info1.Update.called)83 self.assertFalse(dep_info2.Update.called)8485 # Multiple dependencies, multiple platforms in a BaseConfig.86 dep_manager._lookup_dict = {}87 base_config_mock = mock.MagicMock(spec=dependency_manager.BaseConfig)88 dep1 = 'dependency1'89 dep2 = 'dependency2'90 plat1 = 'platform1'91 plat2 = 'platform2'92 dep_info1 = mock.MagicMock(spec=dependency_manager.DependencyInfo)93 dep_info1.dependency = dep194 dep_info1.platform = plat195 dep_info2 = mock.MagicMock(spec=dependency_manager.DependencyInfo)96 dep_info2.dependency = dep197 dep_info2.platform = plat298 dep_info3 = mock.MagicMock(spec=dependency_manager.DependencyInfo)99 dep_info3.dependency = dep2100 dep_info3.platform = plat2101 base_config_mock.IterDependencyInfo.return_value = iter(102 [dep_info1, dep_info2, dep_info3])103 expected_lookup_dict = {dep1: {plat1: dep_info1,104 plat2: dep_info2},105 dep2: {plat2: dep_info3}}106 dep_manager._UpdateDependencies(base_config_mock)107 self.assertEqual(expected_lookup_dict, dep_manager._lookup_dict)108 self.assertFalse(dep_info1.Update.called)109 self.assertFalse(dep_info2.Update.called)110 self.assertFalse(dep_info3.Update.called)111112 def testFollowupUpdateDependenciesNoOverlap(self):113 dep_manager = dependency_manager.DependencyManager([])114 dep = 'dependency'115 dep1 = 'dependency1'116 dep2 = 'dependency2'117 dep3 = 'dependency3'118 plat1 = 'platform1'119 plat2 = 'platform2'120 plat3 = 'platform3'121 dep_info_a = mock.MagicMock(spec=dependency_manager.DependencyInfo)122 dep_info_a.dependency = dep1123 dep_info_a.platform = plat1124 dep_info_b = mock.MagicMock(spec=dependency_manager.DependencyInfo)125 dep_info_b.dependency = dep1126 dep_info_b.platform = plat2127 dep_info_c = mock.MagicMock(spec=dependency_manager.DependencyInfo)128 dep_info_c.dependency = dep129 dep_info_c.platform = plat1130131 start_lookup_dict = {dep: {plat1: dep_info_a,132 plat2: dep_info_b},133 dep1: {plat1: dep_info_c}}134 base_config_mock = mock.MagicMock(spec=dependency_manager.BaseConfig)135136 # Empty BaseConfig.137 dep_manager._lookup_dict = start_lookup_dict.copy()138 base_config_mock.IterDependencyInfo.return_value = iter([])139 dep_manager._UpdateDependencies(base_config_mock)140 self.assertEqual(start_lookup_dict, dep_manager._lookup_dict)141142 # One dependency/platform in a BaseConfig.143 dep_manager._lookup_dict = start_lookup_dict.copy()144 dep_info = mock.MagicMock(spec=dependency_manager.DependencyInfo)145 dep_info.dependency = dep3146 dep_info.platform = plat1147 base_config_mock.IterDependencyInfo.return_value = iter([dep_info])148 expected_lookup_dict = {dep: {plat1: dep_info_a,149 plat2: dep_info_b},150 dep1: {plat1: dep_info_c},151 dep3: {plat3: dep_info}}152153 dep_manager._UpdateDependencies(base_config_mock)154 self.assertItemsEqual(expected_lookup_dict, dep_manager._lookup_dict)155 self.assertFalse(dep_info.Update.called)156 self.assertFalse(dep_info_a.Update.called)157 self.assertFalse(dep_info_b.Update.called)158 self.assertFalse(dep_info_c.Update.called)159160 # One dependency multiple platforms in a BaseConfig.161 dep_manager._lookup_dict = start_lookup_dict.copy()162 dep_info1 = mock.MagicMock(spec=dependency_manager.DependencyInfo)163 dep_info1.dependency = dep2164 dep_info1.platform = plat1165 dep_info2 = mock.MagicMock(spec=dependency_manager.DependencyInfo)166 dep_info2.dependency = dep2167 dep_info2.platform = plat2168 base_config_mock.IterDependencyInfo.return_value = iter([dep_info1,169 dep_info2])170 expected_lookup_dict = {dep: {plat1: dep_info_a,171 plat2: dep_info_b},172 dep1: {plat1: dep_info_c},173 dep2: {plat1: dep_info1,174 plat2: dep_info2}}175 dep_manager._UpdateDependencies(base_config_mock)176 self.assertEqual(expected_lookup_dict, dep_manager._lookup_dict)177 self.assertFalse(dep_info1.Update.called)178 self.assertFalse(dep_info2.Update.called)179 self.assertFalse(dep_info_a.Update.called)180 self.assertFalse(dep_info_b.Update.called)181 self.assertFalse(dep_info_c.Update.called)182183 # Multiple dependencies, multiple platforms in a BaseConfig.184 dep_manager._lookup_dict = start_lookup_dict.copy()185 dep1 = 'dependency1'186 plat1 = 'platform1'187 plat2 = 'platform2'188 dep_info1 = mock.MagicMock(spec=dependency_manager.DependencyInfo)189 dep_info1.dependency = dep2190 dep_info1.platform = plat1191 dep_info2 = mock.MagicMock(spec=dependency_manager.DependencyInfo)192 dep_info2.dependency = dep2193 dep_info2.platform = plat2194 dep_info3 = mock.MagicMock(spec=dependency_manager.DependencyInfo)195 dep_info3.dependency = dep3196 dep_info3.platform = plat2197 base_config_mock.IterDependencyInfo.return_value = iter(198 [dep_info1, dep_info2, dep_info3])199 expected_lookup_dict = {dep: {plat1: dep_info_a,200 plat2: dep_info_b},201 dep1: {plat1: dep_info_c},202 dep2: {plat1: dep_info1,203 plat2: dep_info2},204 dep3: {plat2: dep_info3}}205 dep_manager._UpdateDependencies(base_config_mock)206 self.assertEqual(expected_lookup_dict, dep_manager._lookup_dict)207 self.assertFalse(dep_info1.Update.called)208 self.assertFalse(dep_info2.Update.called)209 self.assertFalse(dep_info3.Update.called)210 self.assertFalse(dep_info_a.Update.called)211 self.assertFalse(dep_info_b.Update.called)212 self.assertFalse(dep_info_c.Update.called)213214 # Ensure the testing data wasn't corrupted.215 self.assertEqual(start_lookup_dict,216 {dep: {plat1: dep_info_a,217 plat2: dep_info_b},218 dep1: {plat1: dep_info_c}})219220 def testFollowupUpdateDependenciesWithCollisions(self):221 dep_manager = dependency_manager.DependencyManager([])222 dep = 'dependency'223 dep1 = 'dependency1'224 dep2 = 'dependency2'225 plat1 = 'platform1'226 plat2 = 'platform2'227 dep_info_a = mock.MagicMock(spec=dependency_manager.DependencyInfo)228 dep_info_a.dependency = dep1229 dep_info_a.platform = plat1230 dep_info_b = mock.MagicMock(spec=dependency_manager.DependencyInfo)231 dep_info_b.dependency = dep1232 dep_info_b.platform = plat2233 dep_info_c = mock.MagicMock(spec=dependency_manager.DependencyInfo)234 dep_info_c.dependency = dep235 dep_info_c.platform = plat1236237 start_lookup_dict = {dep: {plat1: dep_info_a,238 plat2: dep_info_b},239 dep1: {plat1: dep_info_c}}240 base_config_mock = mock.MagicMock(spec=dependency_manager.BaseConfig)241242 # One dependency/platform.243 dep_manager._lookup_dict = start_lookup_dict.copy()244 dep_info = mock.MagicMock(spec=dependency_manager.DependencyInfo)245 dep_info.dependency = dep246 dep_info.platform = plat1247 base_config_mock.IterDependencyInfo.return_value = iter([dep_info])248 expected_lookup_dict = {dep: {plat1: dep_info_a,249 plat2: dep_info_b},250 dep1: {plat1: dep_info_c}}251252 dep_manager._UpdateDependencies(base_config_mock)253 self.assertItemsEqual(expected_lookup_dict, dep_manager._lookup_dict)254 dep_info_a.Update.assert_called_once_with(dep_info)255 self.assertFalse(dep_info.Update.called)256 self.assertFalse(dep_info_b.Update.called)257 self.assertFalse(dep_info_c.Update.called)258 dep_info_a.reset_mock()259 dep_info_b.reset_mock()260 dep_info_c.reset_mock()261262 # One dependency multiple platforms in a BaseConfig.263 dep_manager._lookup_dict = start_lookup_dict.copy()264 dep_info1 = mock.MagicMock(spec=dependency_manager.DependencyInfo)265 dep_info1.dependency = dep1266 dep_info1.platform = plat1267 dep_info2 = mock.MagicMock(spec=dependency_manager.DependencyInfo)268 dep_info2.dependency = dep2269 dep_info2.platform = plat2270 base_config_mock.IterDependencyInfo.return_value = iter([dep_info1,271 dep_info2])272 expected_lookup_dict = {dep: {plat1: dep_info_a,273 plat2: dep_info_b},274 dep1: {plat1: dep_info_c},275 dep2: {plat2: dep_info2}}276 dep_manager._UpdateDependencies(base_config_mock)277 self.assertEqual(expected_lookup_dict, dep_manager._lookup_dict)278 self.assertFalse(dep_info1.Update.called)279 self.assertFalse(dep_info2.Update.called)280 self.assertFalse(dep_info_a.Update.called)281 self.assertFalse(dep_info_b.Update.called)282 dep_info_c.Update.assert_called_once_with(dep_info1)283 dep_info_a.reset_mock()284 dep_info_b.reset_mock()285 dep_info_c.reset_mock()286287 # Multiple dependencies, multiple platforms in a BaseConfig.288 dep_manager._lookup_dict = start_lookup_dict.copy()289 dep1 = 'dependency1'290 plat1 = 'platform1'291 plat2 = 'platform2'292 dep_info1 = mock.MagicMock(spec=dependency_manager.DependencyInfo)293 dep_info1.dependency = dep294 dep_info1.platform = plat1295 dep_info2 = mock.MagicMock(spec=dependency_manager.DependencyInfo)296 dep_info2.dependency = dep1297 dep_info2.platform = plat1298 dep_info3 = mock.MagicMock(spec=dependency_manager.DependencyInfo)299 dep_info3.dependency = dep2300 dep_info3.platform = plat2301 base_config_mock.IterDependencyInfo.return_value = iter(302 [dep_info1, dep_info2, dep_info3])303 expected_lookup_dict = {dep: {plat1: dep_info_a,304 plat2: dep_info_b},305 dep1: {plat1: dep_info_c},306 dep2: {plat2: dep_info3}}307 dep_manager._UpdateDependencies(base_config_mock)308 self.assertEqual(expected_lookup_dict, dep_manager._lookup_dict)309 self.assertFalse(dep_info1.Update.called)310 self.assertFalse(dep_info2.Update.called)311 self.assertFalse(dep_info3.Update.called)312 self.assertFalse(dep_info_b.Update.called)313 dep_info_a.Update.assert_called_once_with(dep_info1)314 dep_info_c.Update.assert_called_once_with(dep_info2)315316 # Collision error.317 dep_manager._lookup_dict = start_lookup_dict.copy()318 dep_info = mock.MagicMock(spec=dependency_manager.DependencyInfo)319 dep_info.dependency = dep320 dep_info.platform = plat1321 base_config_mock.IterDependencyInfo.return_value = iter([dep_info])322 dep_info_a.Update.side_effect = ValueError323 self.assertRaises(ValueError,324 dep_manager._UpdateDependencies, base_config_mock)325326 # Ensure the testing data wasn't corrupted.327 self.assertEqual(start_lookup_dict,328 {dep: {plat1: dep_info_a,329 plat2: dep_info_b},330 dep1: {plat1: dep_info_c}})331332 def testGetDependencyInfo(self):333 dep_manager = dependency_manager.DependencyManager([])334 self.assertFalse(dep_manager._lookup_dict)335336 # No dependencies in the dependency manager.337 self.assertEqual(None, dep_manager._GetDependencyInfo('missing_dep',338 'missing_plat'))339340 dep_manager._lookup_dict = {'dep1': {'plat1': 'dep_info11',341 'plat2': 'dep_info12',342 'plat3': 'dep_info13'},343 'dep2': {'plat1': 'dep_info11',344 'plat2': 'dep_info21',345 'plat3': 'dep_info23',346 'default': 'dep_info2d'},347 'dep3': {'plat1': 'dep_info31',348 'plat2': 'dep_info32',349 'default': 'dep_info3d'}}350 # Dependency not in the dependency manager.351 self.assertEqual(None, dep_manager._GetDependencyInfo(352 'missing_dep', 'missing_plat'))353 # Dependency in the dependency manager, but not the platform. No default.354 self.assertEqual(None, dep_manager._GetDependencyInfo(355 'dep1', 'missing_plat'))356 # Dependency in the dependency manager, but not the platform, but a default357 # exists.358 self.assertEqual('dep_info2d', dep_manager._GetDependencyInfo(359 'dep2', 'missing_plat'))360 # Dependency and platform in the dependency manager. A default exists.361 self.assertEqual('dep_info23', dep_manager._GetDependencyInfo(362 'dep2', 'plat3'))363 # Dependency and platform in the dependency manager. No default exists.364 self.assertEqual('dep_info12', dep_manager._GetDependencyInfo(365 'dep1', 'plat2'))366367368369370371372373374375376377378379380381382383384 @mock.patch(385 'dependency_manager.dependency_info.DependencyInfo.GetRemotePath') # pylint: disable=line-too-long386 def testFetchPathUnititializedDependency(387 self, cs_path_mock):388 dep_manager = dependency_manager.DependencyManager([])389 self.assertFalse(cs_path_mock.call_args)390 cs_path = 'cs_path'391 cs_path_mock.return_value = cs_path392393 # Empty lookup_dict394 with self.assertRaises(exceptions.NoPathFoundError):395 dep_manager.FetchPath('dep', 'plat_arch_x86')396397 # Non-empty lookup dict that doesn't contain the dependency we're looking398 # for.399 dep_manager._lookup_dict = {'dep1': mock.MagicMock(),400 'dep2': mock.MagicMock()}401 with self.assertRaises(exceptions.NoPathFoundError):402 dep_manager.FetchPath('dep', 'plat_arch_x86')403404 @mock.patch('os.path')405 @mock.patch(406 'dependency_manager.DependencyManager._GetDependencyInfo')407 @mock.patch(408 'dependency_manager.dependency_info.DependencyInfo.GetRemotePath') # pylint: disable=line-too-long409 def testFetchPathLocalFile(self, cs_path_mock, dep_info_mock, path_mock):410 dep_manager = dependency_manager.DependencyManager([])411 self.assertFalse(cs_path_mock.call_args)412 cs_path = 'cs_path'413 dep_info = self.dep_info414 cs_path_mock.return_value = cs_path415 # The DependencyInfo returned should be passed through to LocalPath.416 dep_info_mock.return_value = dep_info417418 # Non-empty lookup dict that contains the dependency we're looking for.419 # Local path exists.420 dep_manager._lookup_dict = {'dep': {'platform' : self.dep_info},421 'dep2': mock.MagicMock()}422 self.fs.CreateFile('path1')423 found_path = dep_manager.FetchPath('dep', 'platform')424425 self.assertEqual('path1', found_path)426 self.assertFalse(cs_path_mock.call_args)427428429 @mock.patch(430 'dependency_manager.dependency_info.DependencyInfo.GetRemotePath') # pylint: disable=line-too-long431 def testFetchPathRemoteFile(432 self, cs_path_mock):433 dep_manager = dependency_manager.DependencyManager([])434 self.assertFalse(cs_path_mock.call_args)435 cs_path = 'cs_path'436 def FakeCSPath():437 self.fs.CreateFile(cs_path)438 return cs_path439 cs_path_mock.side_effect = FakeCSPath440441 # Non-empty lookup dict that contains the dependency we're looking for.442 # Local path doesn't exist, but cloud_storage_path is downloaded.443 dep_manager._lookup_dict = {'dep': {'platform' : self.dep_info,444 'plat1': mock.MagicMock()},445 'dep2': {'plat2': mock.MagicMock()}}446 found_path = dep_manager.FetchPath('dep', 'platform')447 self.assertEqual(cs_path, found_path)448449450 @mock.patch(451 'dependency_manager.dependency_info.DependencyInfo.GetRemotePath') # pylint: disable=line-too-long452 def testFetchPathError(453 self, cs_path_mock):454 dep_manager = dependency_manager.DependencyManager([])455 self.assertFalse(cs_path_mock.call_args)456 cs_path_mock.return_value = None457 dep_manager._lookup_dict = {'dep': {'platform' : self.dep_info,458 'plat1': mock.MagicMock()},459 'dep2': {'plat2': mock.MagicMock()}}460 # Non-empty lookup dict that contains the dependency we're looking for.461 # Local path doesn't exist, and cloud_storage path wasn't successfully462 # found.463 self.assertRaises(exceptions.NoPathFoundError,464 dep_manager.FetchPath, 'dep', 'platform')465466 cs_path_mock.side_effect = cloud_storage.CredentialsError467 self.assertRaises(cloud_storage.CredentialsError,468 dep_manager.FetchPath, 'dep', 'platform')469470 cs_path_mock.side_effect = cloud_storage.CloudStorageError471 self.assertRaises(cloud_storage.CloudStorageError,472 dep_manager.FetchPath, 'dep', 'platform')473474 cs_path_mock.side_effect = cloud_storage.PermissionError475 self.assertRaises(cloud_storage.PermissionError,476 dep_manager.FetchPath, 'dep', 'platform')477478 def testLocalPath(self):479 dep_manager = dependency_manager.DependencyManager([])480 # Empty lookup_dict481 with self.assertRaises(exceptions.NoPathFoundError):482 dep_manager.LocalPath('dep', 'plat')483484 def testLocalPathNoDependency(self):485 # Non-empty lookup dict that doesn't contain the dependency we're looking486 # for.487 dep_manager = dependency_manager.DependencyManager([])488 dep_manager._lookup_dict = {'dep1': mock.MagicMock(),489 'dep2': mock.MagicMock()}490 with self.assertRaises(exceptions.NoPathFoundError):491 dep_manager.LocalPath('dep', 'plat')492493 def testLocalPathExists(self):494 # Non-empty lookup dict that contains the dependency we're looking for.495 # Local path exists.496 dep_manager = dependency_manager.DependencyManager([])497 dep_manager._lookup_dict = {'dependency' : {'platform': self.dep_info},498 'dep1': mock.MagicMock(),499 'dep2': mock.MagicMock()}500 self.fs.CreateFile('path1')501 found_path = dep_manager.LocalPath('dependency', 'platform')502503 self.assertEqual('path1', found_path)504505 def testLocalPathMissingPaths(self):506 # Non-empty lookup dict that contains the dependency we're looking for.507 # Local path is found but doesn't exist.508 dep_manager = dependency_manager.DependencyManager([])509 dep_manager._lookup_dict = {'dependency' : {'platform': self.dep_info},510 'dep1': mock.MagicMock(),511 'dep2': mock.MagicMock()}512 self.assertRaises(exceptions.NoPathFoundError,513 dep_manager.LocalPath, 'dependency', 'platform')514515 def testLocalPathNoPaths(self):516 # Non-empty lookup dict that contains the dependency we're looking for.517 # Local path isn't found.518 dep_manager = dependency_manager.DependencyManager([])519 dep_info = dependency_manager.DependencyInfo(520 'dep', 'platform', 'config_file',521 cloud_storage_info=self.cloud_storage_info)522 dep_manager._lookup_dict = {'dependency' : {'platform': dep_info},523 'dep1': mock.MagicMock(),524 'dep2': mock.MagicMock()}525 self.assertRaises(exceptions.NoPathFoundError,526 dep_manager.LocalPath, 'dependency', 'platform') ...

Full Screen

Full Screen

test_edge_data.py

Source:test_edge_data.py Github

copy

Full Screen

1import os2import sys3if sys.version_info[:2] <= (2,6):4 import unittest2 as unittest5else:6 import unittest7from modulegraph import modulegraph8# XXX: Todo: simular tests with bytecompiled modules9class TestEdgeData (unittest.TestCase):10 if not hasattr(unittest.TestCase, 'assertIsInstance'):11 def assertIsInstance(self, value, types):12 if not isinstance(value, types):13 self.fail("%r is not an instance of %r"%(value, types))14 def test_regular_import(self):15 root = os.path.join(16 os.path.dirname(os.path.abspath(__file__)),17 'testpkg-edgedata')18 mf = modulegraph.ModuleGraph(path=[ root ] + sys.path)19 script_name = os.path.join(root, 'script.py')20 mf.run_script(script_name)21 script_node = mf.findNode(script_name)22 self.assertIsInstance(script_node, modulegraph.Script)23 node = mf.findNode('toplevel_existing')24 self.assertIsInstance(node, modulegraph.SourceModule)25 ed = mf.edgeData(script_node, node)26 self.assertIsInstance(ed, modulegraph.DependencyInfo)27 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=False, tryexcept=False, fromlist=False))28 node = mf.findNode('toplevel_nonexisting')29 self.assertIsInstance(node, modulegraph.MissingModule)30 ed = mf.edgeData(script_node, node)31 self.assertIsInstance(ed, modulegraph.DependencyInfo)32 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=False, tryexcept=False, fromlist=False))33 node = mf.findNode('toplevel_class_existing')34 self.assertIsInstance(node, modulegraph.SourceModule)35 ed = mf.edgeData(script_node, node)36 self.assertIsInstance(ed, modulegraph.DependencyInfo)37 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=False, tryexcept=False, fromlist=False))38 node = mf.findNode('toplevel_class_nonexisting')39 self.assertIsInstance(node, modulegraph.MissingModule)40 ed = mf.edgeData(script_node, node)41 self.assertIsInstance(ed, modulegraph.DependencyInfo)42 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=False, tryexcept=False, fromlist=False))43 node = mf.findNode('toplevel_conditional_existing')44 self.assertIsInstance(node, modulegraph.SourceModule)45 ed = mf.edgeData(script_node, node)46 self.assertIsInstance(ed, modulegraph.DependencyInfo)47 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=False, tryexcept=False, fromlist=False))48 node = mf.findNode('toplevel_conditional_nonexisting')49 self.assertIsInstance(node, modulegraph.MissingModule)50 ed = mf.edgeData(script_node, node)51 self.assertIsInstance(ed, modulegraph.DependencyInfo)52 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=False, tryexcept=False, fromlist=False))53 node = mf.findNode('toplevel_conditional_import_existing')54 self.assertIsInstance(node, modulegraph.SourceModule)55 ed = mf.edgeData(script_node, node)56 self.assertIsInstance(ed, modulegraph.DependencyInfo)57 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=False, tryexcept=True, fromlist=False))58 node = mf.findNode('toplevel_conditional_import_nonexisting')59 self.assertIsInstance(node, modulegraph.MissingModule)60 ed = mf.edgeData(script_node, node)61 self.assertIsInstance(ed, modulegraph.DependencyInfo)62 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=False, tryexcept=True, fromlist=False))63 node = mf.findNode('toplevel_conditional_import2_existing')64 self.assertIsInstance(node, modulegraph.SourceModule)65 ed = mf.edgeData(script_node, node)66 self.assertIsInstance(ed, modulegraph.DependencyInfo)67 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=False, tryexcept=True, fromlist=False))68 node = mf.findNode('toplevel_conditional_import2_nonexisting')69 self.assertIsInstance(node, modulegraph.MissingModule)70 ed = mf.edgeData(script_node, node)71 self.assertIsInstance(ed, modulegraph.DependencyInfo)72 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=False, tryexcept=True, fromlist=False))73 node = mf.findNode('toplevel_import_existing')74 self.assertIsInstance(node, modulegraph.SourceModule)75 ed = mf.edgeData(script_node, node)76 self.assertIsInstance(ed, modulegraph.DependencyInfo)77 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=False, tryexcept=True, fromlist=False))78 node = mf.findNode('toplevel_import_nonexisting')79 self.assertIsInstance(node, modulegraph.MissingModule)80 ed = mf.edgeData(script_node, node)81 self.assertIsInstance(ed, modulegraph.DependencyInfo)82 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=False, tryexcept=True, fromlist=False))83 node = mf.findNode('toplevel_import2_existing')84 self.assertIsInstance(node, modulegraph.SourceModule)85 ed = mf.edgeData(script_node, node)86 self.assertIsInstance(ed, modulegraph.DependencyInfo)87 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=False, tryexcept=True, fromlist=False))88 node = mf.findNode('toplevel_import2_nonexisting')89 self.assertIsInstance(node, modulegraph.MissingModule)90 ed = mf.edgeData(script_node, node)91 self.assertIsInstance(ed, modulegraph.DependencyInfo)92 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=False, tryexcept=True, fromlist=False))93 node = mf.findNode('function_existing')94 self.assertIsInstance(node, modulegraph.SourceModule)95 ed = mf.edgeData(script_node, node)96 self.assertIsInstance(ed, modulegraph.DependencyInfo)97 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=True, tryexcept=False, fromlist=False))98 node = mf.findNode('function_nonexisting')99 self.assertIsInstance(node, modulegraph.MissingModule)100 ed = mf.edgeData(script_node, node)101 self.assertIsInstance(ed, modulegraph.DependencyInfo)102 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=True, tryexcept=False, fromlist=False))103 node = mf.findNode('function_class_existing')104 self.assertIsInstance(node, modulegraph.SourceModule)105 ed = mf.edgeData(script_node, node)106 self.assertIsInstance(ed, modulegraph.DependencyInfo)107 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=True, tryexcept=False, fromlist=False))108 node = mf.findNode('function_class_nonexisting')109 self.assertIsInstance(node, modulegraph.MissingModule)110 ed = mf.edgeData(script_node, node)111 self.assertIsInstance(ed, modulegraph.DependencyInfo)112 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=True, tryexcept=False, fromlist=False))113 node = mf.findNode('function_conditional_existing')114 self.assertIsInstance(node, modulegraph.SourceModule)115 ed = mf.edgeData(script_node, node)116 self.assertIsInstance(ed, modulegraph.DependencyInfo)117 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=True, tryexcept=False, fromlist=False))118 node = mf.findNode('function_conditional_nonexisting')119 self.assertIsInstance(node, modulegraph.MissingModule)120 ed = mf.edgeData(script_node, node)121 self.assertIsInstance(ed, modulegraph.DependencyInfo)122 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=True, tryexcept=False, fromlist=False))123 node = mf.findNode('function_conditional_import_existing')124 self.assertIsInstance(node, modulegraph.SourceModule)125 ed = mf.edgeData(script_node, node)126 self.assertIsInstance(ed, modulegraph.DependencyInfo)127 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=True, tryexcept=True, fromlist=False))128 node = mf.findNode('function_conditional_import_nonexisting')129 self.assertIsInstance(node, modulegraph.MissingModule)130 ed = mf.edgeData(script_node, node)131 self.assertIsInstance(ed, modulegraph.DependencyInfo)132 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=True, tryexcept=True, fromlist=False))133 node = mf.findNode('function_conditional_import2_existing')134 self.assertIsInstance(node, modulegraph.SourceModule)135 ed = mf.edgeData(script_node, node)136 self.assertIsInstance(ed, modulegraph.DependencyInfo)137 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=True, tryexcept=True, fromlist=False))138 node = mf.findNode('function_conditional_import2_nonexisting')139 self.assertIsInstance(node, modulegraph.MissingModule)140 ed = mf.edgeData(script_node, node)141 self.assertIsInstance(ed, modulegraph.DependencyInfo)142 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=True, tryexcept=True, fromlist=False))143 node = mf.findNode('function_import_existing')144 self.assertIsInstance(node, modulegraph.SourceModule)145 ed = mf.edgeData(script_node, node)146 self.assertIsInstance(ed, modulegraph.DependencyInfo)147 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=True, tryexcept=True, fromlist=False))148 node = mf.findNode('function_import_nonexisting')149 self.assertIsInstance(node, modulegraph.MissingModule)150 ed = mf.edgeData(script_node, node)151 self.assertIsInstance(ed, modulegraph.DependencyInfo)152 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=True, tryexcept=True, fromlist=False))153 node = mf.findNode('function_import2_existing')154 self.assertIsInstance(node, modulegraph.SourceModule)155 ed = mf.edgeData(script_node, node)156 self.assertIsInstance(ed, modulegraph.DependencyInfo)157 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=True, tryexcept=True, fromlist=False))158 node = mf.findNode('function_import2_nonexisting')159 self.assertIsInstance(node, modulegraph.MissingModule)160 ed = mf.edgeData(script_node, node)161 self.assertIsInstance(ed, modulegraph.DependencyInfo)162 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=True, tryexcept=True, fromlist=False))163 def test_multi_import(self):164 root = os.path.join(165 os.path.dirname(os.path.abspath(__file__)),166 'testpkg-edgedata')167 mf = modulegraph.ModuleGraph(path=[ root ] + sys.path)168 script_name = os.path.join(root, 'script_multi_import.py')169 mf.run_script(script_name)170 script_node = mf.findNode(script_name)171 self.assertIsInstance(script_node, modulegraph.Script)172 node = mf.findNode('os.path')173 ed = mf.edgeData(script_node, node)174 self.assertIsInstance(ed, modulegraph.DependencyInfo)175 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=False, tryexcept=True, fromlist=False))176 node = mf.findNode('os')177 ed = mf.edgeData(script_node, node)178 self.assertIsInstance(ed, modulegraph.DependencyInfo)179 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=False, tryexcept=False, fromlist=False))180 node = mf.findNode('sys')181 ed = mf.edgeData(script_node, node)182 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=True, tryexcept=False, fromlist=False))183 node = mf.findNode('platform')184 ed = mf.edgeData(script_node, node)185 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=True, tryexcept=False, fromlist=False))186 node = mf.findNode('email')187 ed = mf.edgeData(script_node, node)188 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=False, tryexcept=False, fromlist=False))189 def test_from_imports(self):190 root = os.path.join(191 os.path.dirname(os.path.abspath(__file__)),192 'testpkg-edgedata')193 mf = modulegraph.ModuleGraph(path=[ root ] + sys.path)194 script_name = os.path.join(root, 'script_from_import.py')195 mf.run_script(script_name)196 script_node = mf.findNode(script_name)197 self.assertIsInstance(script_node, modulegraph.Script)198 node = mf.findNode('pkg.toplevel_existing')199 self.assertIsInstance(node, modulegraph.SourceModule)200 ed = mf.edgeData(script_node, node)201 self.assertIsInstance(ed, modulegraph.DependencyInfo)202 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=False, tryexcept=False, fromlist=True))203 node = mf.findNode('pkg.toplevel_nonexisting')204 self.assertIsInstance(node, modulegraph.MissingModule)205 ed = mf.edgeData(script_node, node)206 self.assertIsInstance(ed, modulegraph.DependencyInfo)207 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=False, tryexcept=False, fromlist=True))208 node = mf.findNode('pkg.toplevel_class_existing')209 self.assertIsInstance(node, modulegraph.SourceModule)210 ed = mf.edgeData(script_node, node)211 self.assertIsInstance(ed, modulegraph.DependencyInfo)212 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=False, tryexcept=False, fromlist=True))213 node = mf.findNode('pkg.toplevel_class_nonexisting')214 self.assertIsInstance(node, modulegraph.MissingModule)215 ed = mf.edgeData(script_node, node)216 self.assertIsInstance(ed, modulegraph.DependencyInfo)217 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=False, tryexcept=False, fromlist=True))218 node = mf.findNode('pkg.toplevel_conditional_existing')219 self.assertIsInstance(node, modulegraph.SourceModule)220 ed = mf.edgeData(script_node, node)221 self.assertIsInstance(ed, modulegraph.DependencyInfo)222 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=False, tryexcept=False, fromlist=True))223 node = mf.findNode('pkg.toplevel_conditional_nonexisting')224 self.assertIsInstance(node, modulegraph.MissingModule)225 ed = mf.edgeData(script_node, node)226 self.assertIsInstance(ed, modulegraph.DependencyInfo)227 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=False, tryexcept=False, fromlist=True))228 node = mf.findNode('pkg.toplevel_conditional_import_existing')229 self.assertIsInstance(node, modulegraph.SourceModule)230 ed = mf.edgeData(script_node, node)231 self.assertIsInstance(ed, modulegraph.DependencyInfo)232 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=False, tryexcept=True, fromlist=True))233 node = mf.findNode('pkg.toplevel_conditional_import_nonexisting')234 self.assertIsInstance(node, modulegraph.MissingModule)235 ed = mf.edgeData(script_node, node)236 self.assertIsInstance(ed, modulegraph.DependencyInfo)237 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=False, tryexcept=True, fromlist=True))238 node = mf.findNode('pkg.toplevel_conditional_import2_existing')239 self.assertIsInstance(node, modulegraph.SourceModule)240 ed = mf.edgeData(script_node, node)241 self.assertIsInstance(ed, modulegraph.DependencyInfo)242 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=False, tryexcept=True, fromlist=True))243 node = mf.findNode('pkg.toplevel_conditional_import2_nonexisting')244 self.assertIsInstance(node, modulegraph.MissingModule)245 ed = mf.edgeData(script_node, node)246 self.assertIsInstance(ed, modulegraph.DependencyInfo)247 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=False, tryexcept=True, fromlist=True))248 node = mf.findNode('pkg.toplevel_import_existing')249 self.assertIsInstance(node, modulegraph.SourceModule)250 ed = mf.edgeData(script_node, node)251 self.assertIsInstance(ed, modulegraph.DependencyInfo)252 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=False, tryexcept=True, fromlist=True))253 node = mf.findNode('pkg.toplevel_import_nonexisting')254 self.assertIsInstance(node, modulegraph.MissingModule)255 ed = mf.edgeData(script_node, node)256 self.assertIsInstance(ed, modulegraph.DependencyInfo)257 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=False, tryexcept=True, fromlist=True))258 node = mf.findNode('pkg.toplevel_import2_existing')259 self.assertIsInstance(node, modulegraph.SourceModule)260 ed = mf.edgeData(script_node, node)261 self.assertIsInstance(ed, modulegraph.DependencyInfo)262 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=False, tryexcept=True, fromlist=True))263 node = mf.findNode('pkg.toplevel_import2_nonexisting')264 self.assertIsInstance(node, modulegraph.MissingModule)265 ed = mf.edgeData(script_node, node)266 self.assertIsInstance(ed, modulegraph.DependencyInfo)267 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=False, tryexcept=True, fromlist=True))268 node = mf.findNode('pkg.function_existing')269 self.assertIsInstance(node, modulegraph.SourceModule)270 ed = mf.edgeData(script_node, node)271 self.assertIsInstance(ed, modulegraph.DependencyInfo)272 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=True, tryexcept=False, fromlist=True))273 node = mf.findNode('pkg.function_nonexisting')274 self.assertIsInstance(node, modulegraph.MissingModule)275 ed = mf.edgeData(script_node, node)276 self.assertIsInstance(ed, modulegraph.DependencyInfo)277 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=True, tryexcept=False, fromlist=True))278 node = mf.findNode('pkg.function_class_existing')279 self.assertIsInstance(node, modulegraph.SourceModule)280 ed = mf.edgeData(script_node, node)281 self.assertIsInstance(ed, modulegraph.DependencyInfo)282 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=True, tryexcept=False, fromlist=True))283 node = mf.findNode('pkg.function_class_nonexisting')284 self.assertIsInstance(node, modulegraph.MissingModule)285 ed = mf.edgeData(script_node, node)286 self.assertIsInstance(ed, modulegraph.DependencyInfo)287 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=True, tryexcept=False, fromlist=True))288 node = mf.findNode('pkg.function_conditional_existing')289 self.assertIsInstance(node, modulegraph.SourceModule)290 ed = mf.edgeData(script_node, node)291 self.assertIsInstance(ed, modulegraph.DependencyInfo)292 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=True, tryexcept=False, fromlist=True))293 node = mf.findNode('pkg.function_conditional_nonexisting')294 self.assertIsInstance(node, modulegraph.MissingModule)295 ed = mf.edgeData(script_node, node)296 self.assertIsInstance(ed, modulegraph.DependencyInfo)297 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=True, tryexcept=False, fromlist=True))298 node = mf.findNode('pkg.function_conditional_import_existing')299 self.assertIsInstance(node, modulegraph.SourceModule)300 ed = mf.edgeData(script_node, node)301 self.assertIsInstance(ed, modulegraph.DependencyInfo)302 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=True, tryexcept=True, fromlist=True))303 node = mf.findNode('pkg.function_conditional_import_nonexisting')304 self.assertIsInstance(node, modulegraph.MissingModule)305 ed = mf.edgeData(script_node, node)306 self.assertIsInstance(ed, modulegraph.DependencyInfo)307 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=True, tryexcept=True, fromlist=True))308 node = mf.findNode('pkg.function_conditional_import2_existing')309 self.assertIsInstance(node, modulegraph.SourceModule)310 ed = mf.edgeData(script_node, node)311 self.assertIsInstance(ed, modulegraph.DependencyInfo)312 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=True, tryexcept=True, fromlist=True))313 node = mf.findNode('pkg.function_conditional_import2_nonexisting')314 self.assertIsInstance(node, modulegraph.MissingModule)315 ed = mf.edgeData(script_node, node)316 self.assertIsInstance(ed, modulegraph.DependencyInfo)317 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=True, function=True, tryexcept=True, fromlist=True))318 node = mf.findNode('pkg.function_import_existing')319 self.assertIsInstance(node, modulegraph.SourceModule)320 ed = mf.edgeData(script_node, node)321 self.assertIsInstance(ed, modulegraph.DependencyInfo)322 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=True, tryexcept=True, fromlist=True))323 node = mf.findNode('pkg.function_import_nonexisting')324 self.assertIsInstance(node, modulegraph.MissingModule)325 ed = mf.edgeData(script_node, node)326 self.assertIsInstance(ed, modulegraph.DependencyInfo)327 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=True, tryexcept=True, fromlist=True))328 node = mf.findNode('pkg.function_import2_existing')329 self.assertIsInstance(node, modulegraph.SourceModule)330 ed = mf.edgeData(script_node, node)331 self.assertIsInstance(ed, modulegraph.DependencyInfo)332 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=True, tryexcept=True, fromlist=True))333 node = mf.findNode('pkg.function_import2_nonexisting')334 self.assertIsInstance(node, modulegraph.MissingModule)335 ed = mf.edgeData(script_node, node)336 self.assertIsInstance(ed, modulegraph.DependencyInfo)337 self.assertEqual(ed, modulegraph.DependencyInfo(conditional=False, function=True, tryexcept=True, fromlist=True))338if __name__ == "__main__":...

Full Screen

Full Screen

test_dependency_graph.py

Source:test_dependency_graph.py Github

copy

Full Screen

...12from pypi2nix.wheel import Wheel13def test_can_set_runtime_dependencies(14 package_a: Requirement, package_b: Requirement, dependency_graph: DependencyGraph15):16 dependency_graph.set_runtime_dependency(dependent=package_a, dependency=package_b)17 assert dependency_graph.is_runtime_dependency(18 dependent=package_a, dependency=package_b19 )20def test_can_detect_indirect_runtime_dependencies(21 package_a: Requirement,22 package_b: Requirement,23 package_c: Requirement,24 dependency_graph: DependencyGraph,25) -> None:26 dependency_graph.set_runtime_dependency(dependent=package_a, dependency=package_b)27 dependency_graph.set_runtime_dependency(dependent=package_b, dependency=package_c)28 assert dependency_graph.is_runtime_dependency(29 dependent=package_a, dependency=package_c30 )31def test_cyclic_runtime_dependencies_not_allowed(32 package_a: Requirement, package_b: Requirement, dependency_graph: DependencyGraph33):34 dependency_graph.set_runtime_dependency(dependent=package_a, dependency=package_b)35 with pytest.raises(CyclicDependencyOccured):36 dependency_graph.set_runtime_dependency(37 dependent=package_b, dependency=package_a38 )39def test_can_retriev_all_runtime_dependency_names(40 package_a: Requirement,41 package_b: Requirement,42 package_c: Requirement,43 dependency_graph: DependencyGraph,44) -> None:45 dependency_graph.set_runtime_dependency(dependent=package_a, dependency=package_b)46 dependency_graph.set_runtime_dependency(dependent=package_b, dependency=package_c)47 assert dependency_graph.get_all_runtime_dependency_names(package_a) == {48 package_a.name(),49 package_b.name(),50 package_c.name(),51 }52def test_can_set_buildtime_dependency(53 package_a: Requirement, package_b: Requirement, dependency_graph: DependencyGraph54):55 dependency_graph.set_buildtime_dependency(dependent=package_a, dependency=package_b)56 assert dependency_graph.is_buildtime_dependency(57 dependent=package_a, dependency=package_b58 )59def test_build_time_dependencies_dont_show_up_as_runtime_dependencies(60 package_a: Requirement,61 package_b: Requirement,62 package_c: Requirement,63 dependency_graph: DependencyGraph,64):65 dependency_graph.set_runtime_dependency(dependent=package_a, dependency=package_b)66 dependency_graph.set_buildtime_dependency(dependent=package_b, dependency=package_c)67 assert not dependency_graph.is_runtime_dependency(68 dependent=package_a, dependency=package_c69 )70def test_cannot_add_circular_buildtime_dependencies(71 package_a: Requirement, package_b: Requirement, dependency_graph: DependencyGraph,72):73 dependency_graph.set_buildtime_dependency(dependent=package_a, dependency=package_b)74 with pytest.raises(CyclicDependencyOccured):75 dependency_graph.set_buildtime_dependency(76 dependent=package_b, dependency=package_a77 )78def test_cannot_add_circular_builtime_dependency_to_runtime_dependency(79 package_a: Requirement, package_b: Requirement, dependency_graph: DependencyGraph,80):81 dependency_graph.set_runtime_dependency(dependent=package_a, dependency=package_b)82 with pytest.raises(CyclicDependencyOccured):83 dependency_graph.set_buildtime_dependency(84 dependent=package_b, dependency=package_a85 )86def test_cannot_add_circular_runtime_dependency_to_buildtime_dependency(87 package_a: Requirement, package_b: Requirement, dependency_graph: DependencyGraph,88):89 dependency_graph.set_buildtime_dependency(dependent=package_a, dependency=package_b)90 with pytest.raises(CyclicDependencyOccured):91 dependency_graph.set_runtime_dependency(92 dependent=package_b, dependency=package_a93 )94def test_can_add_two_dependencies_graphs_and_runtime_dependencies_are_also_added(95 package_a: Requirement,96 package_b: Requirement,97 package_c: Requirement,98 dependency_graph: DependencyGraph,99):100 other_dependency_graph = copy(dependency_graph)101 dependency_graph.set_runtime_dependency(dependent=package_a, dependency=package_b)102 other_dependency_graph.set_runtime_dependency(103 dependent=package_b, dependency=package_c104 )105 sum_graph = dependency_graph + other_dependency_graph106 assert not dependency_graph.is_runtime_dependency(107 dependent=package_a, dependency=package_c108 )109 assert not other_dependency_graph.is_runtime_dependency(110 dependent=package_a, dependency=package_c111 )112 assert sum_graph.is_runtime_dependency(dependent=package_a, dependency=package_c)113def test_can_add_two_dependencies_graphs_and_buildtime_dependencies_are_also_added(114 package_a: Requirement,115 package_b: Requirement,116 package_c: Requirement,117 dependency_graph: DependencyGraph,118):119 other_dependency_graph = copy(dependency_graph)120 dependency_graph.set_buildtime_dependency(dependent=package_a, dependency=package_b)121 other_dependency_graph.set_buildtime_dependency(122 dependent=package_b, dependency=package_c123 )124 sum_graph = dependency_graph + other_dependency_graph125 assert not dependency_graph.is_buildtime_dependency(126 dependent=package_a, dependency=package_c127 )128 assert not other_dependency_graph.is_buildtime_dependency(129 dependent=package_a, dependency=package_c130 )131 assert sum_graph.is_buildtime_dependency(dependent=package_a, dependency=package_c)132def test_can_detect_external_dependencies_for_packages(133 package_a: Requirement,134 external_dependency_a: ExternalDependency,135 dependency_graph: DependencyGraph,136):137 dependency_graph.set_external_dependency(138 dependent=package_a, dependency=external_dependency_a139 )140 assert dependency_graph.get_all_external_dependencies(package_a) == {141 external_dependency_a,142 }143def test_can_retrieve_external_dependencies_from_runtime_dependencies(144 package_a: Requirement,145 package_b: Requirement,146 external_dependency_a: ExternalDependency,147 dependency_graph: DependencyGraph,148):149 dependency_graph.set_runtime_dependency(dependent=package_a, dependency=package_b)150 dependency_graph.set_external_dependency(151 dependent=package_b, dependency=external_dependency_a152 )153 assert dependency_graph.get_all_external_dependencies(package=package_a) == {154 external_dependency_a,155 }156def test_can_retrieve_external_dependencies_after_adding_graphs(157 package_a: Requirement,158 package_b: Requirement,159 external_dependency_a: ExternalDependency,160 external_dependency_b: ExternalDependency,161 dependency_graph: DependencyGraph,162):163 other_dependency_graph = copy(dependency_graph)164 dependency_graph.set_external_dependency(165 dependent=package_a, dependency=external_dependency_a166 )167 dependency_graph.set_runtime_dependency(dependent=package_a, dependency=package_b)168 other_dependency_graph.set_external_dependency(169 dependent=package_b, dependency=external_dependency_b170 )171 sum_graph = dependency_graph + other_dependency_graph172 assert sum_graph.get_all_external_dependencies(package=package_a) == {173 external_dependency_a,174 external_dependency_b,175 }176def test_can_understand_wheel_dependecies(177 current_platform: TargetPlatform, requirement_parser: RequirementParser178):179 runtime_dependencies = RequirementSet(current_platform)180 runtime_dependency = requirement_parser.parse("runtime_dependency")181 runtime_dependencies.add(runtime_dependency)182 build_dependencies = RequirementSet(current_platform)183 build_dependency = requirement_parser.parse("build_dependency")184 build_dependencies.add(build_dependency)185 wheel = Wheel(186 name="testpackage",187 version="",188 deps=runtime_dependencies,189 target_platform=current_platform,190 license="",191 homepage="",192 description="",193 build_dependencies=build_dependencies,194 )195 requirement = requirement_parser.parse("testpackage")196 dependency_graph = DependencyGraph()197 dependency_graph.import_wheel(wheel, requirement_parser)198 assert dependency_graph.is_buildtime_dependency(requirement, build_dependency)199 assert dependency_graph.is_runtime_dependency(requirement, runtime_dependency)200@pytest.fixture201def package_a(logger: Logger) -> Requirement:202 return VersionRequirement(203 name="package-a",204 versions=[],205 extras=set(),206 environment_markers=None,207 logger=logger,208 )209@pytest.fixture210def package_b(logger: Logger) -> Requirement:211 return VersionRequirement(212 name="package-b",213 versions=[],...

Full Screen

Full Screen

test_dumbmake.py

Source:test_dumbmake.py Github

copy

Full Screen

1# This Source Code Form is subject to the terms of the Mozilla Public2# License, v. 2.0. If a copy of the MPL was not distributed with this file,3# You can obtain one at http://mozilla.org/MPL/2.0/.4from __future__ import unicode_literals5import unittest6from mozunit import (7 main,8)9from dumbmake.dumbmake import (10 add_extra_dependencies,11 all_dependencies,12 dependency_map,13 indentation,14)15class TestDumbmake(unittest.TestCase):16 def test_indentation(self):17 self.assertEqual(indentation(""), 0)18 self.assertEqual(indentation("x"), 0)19 self.assertEqual(indentation(" x"), 1)20 self.assertEqual(indentation("\tx"), 1)21 self.assertEqual(indentation(" \tx"), 2)22 self.assertEqual(indentation("\t x"), 2)23 self.assertEqual(indentation(" x "), 1)24 self.assertEqual(indentation("\tx\t"), 1)25 self.assertEqual(indentation(" x"), 2)26 self.assertEqual(indentation(" x"), 4)27 def test_dependency_map(self):28 self.assertEqual(dependency_map([]), {})29 self.assertEqual(dependency_map(["a"]), {"a": []})30 self.assertEqual(dependency_map(["a", "b"]), {"a": [], "b": []})31 self.assertEqual(dependency_map(["a", "b", "c"]), {"a": [], "b": [], "c": []})32 # indentation33 self.assertEqual(dependency_map(["a", "\tb", "a", "\tc"]), {"a": [], "b": ["a"], "c": ["a"]})34 self.assertEqual(dependency_map(["a", "\tb", "\t\tc"]), {"a": [], "b": ["a"], "c": ["b", "a"]})35 self.assertEqual(dependency_map(["a", "\tb", "\t\tc", "\td", "\te", "f"]), {"a": [], "b": ["a"], "c": ["b", "a"], "d": ["a"], "e": ["a"], "f": []})36 # irregular indentation37 self.assertEqual(dependency_map(["\ta", "b"]), {"a": [], "b": []})38 self.assertEqual(dependency_map(["a", "\t\t\tb", "\t\tc"]), {"a": [], "b": ["a"], "c": ["a"]})39 self.assertEqual(dependency_map(["a", "\t\tb", "\t\t\tc", "\t\td", "\te", "f"]), {"a": [], "b": ["a"], "c": ["b", "a"], "d": ["a"], "e": ["a"], "f": []})40 # repetitions41 self.assertEqual(dependency_map(["a", "\tb", "a", "\tb"]), {"a": [], "b": ["a"]})42 self.assertEqual(dependency_map(["a", "\tb", "\t\tc", "b", "\td", "\t\te"]), {"a": [], "b": ["a"], "d": ["b"], "e": ["d", "b"], "c": ["b", "a"]})43 # cycles are okay44 self.assertEqual(dependency_map(["a", "\tb", "\t\ta"]), {"a": ["b", "a"], "b": ["a"]})45 def test_all_dependencies(self):46 dm = {"a": [], "b": ["a"], "c": ["b", "a"], "d": ["a"], "e": ["a"], "f": []}47 self.assertEqual(all_dependencies("a", dependency_map=dm), ["a"])48 self.assertEqual(all_dependencies("b", dependency_map=dm), ["b", "a"])49 self.assertEqual(all_dependencies("c", "a", "b", dependency_map=dm), ["c", "b", "a"])50 self.assertEqual(all_dependencies("d", dependency_map=dm), ["d", "a"])51 self.assertEqual(all_dependencies("d", "f", "c", dependency_map=dm), ["d", "f", "c", "b", "a"])52 self.assertEqual(all_dependencies("a", "b", dependency_map=dm), ["b", "a"])53 self.assertEqual(all_dependencies("b", "b", dependency_map=dm), ["b", "a"])54 def test_missing_entry(self):55 # a depends on b, which is missing56 dm = {"a": ["b"]}57 self.assertEqual(all_dependencies("a", dependency_map=dm), ["a", "b"])58 self.assertEqual(all_dependencies("a", "b", dependency_map=dm), ["a", "b"])59 self.assertEqual(all_dependencies("b", dependency_map=dm), ["b"])60 def test_two_dependencies(self):61 dm = {"a": ["c"], "b": ["c"], "c": []}62 # suppose a and b both depend on c. Then we want to build a and b before c...63 self.assertEqual(all_dependencies("a", "b", dependency_map=dm), ["a", "b", "c"])64 # ... but relative order is preserved.65 self.assertEqual(all_dependencies("b", "a", dependency_map=dm), ["b", "a", "c"])66 def test_nested_dependencies(self):67 # a depends on b depends on c depends on d68 dm = {"a": ["b", "c", "d"], "b": ["c", "d"], "c": ["d"]}69 self.assertEqual(all_dependencies("b", "a", dependency_map=dm), ["a", "b", "c", "d"])70 self.assertEqual(all_dependencies("c", "a", dependency_map=dm), ["a", "b", "c", "d"])71 def test_add_extra_dependencies(self):72 # a depends on b depends on c depends on d73 dm = {"a": ["b", "c", "d"], "b": ["c", "d"], "c": ["d"]}74 # Edge cases.75 self.assertEqual(list(add_extra_dependencies([], dependency_map=dm)),76 [])77 self.assertEqual(list(add_extra_dependencies([(None, "package")], dependency_map=dm)),78 [(None, "package")])79 # Easy expansion.80 self.assertEqual(list(add_extra_dependencies([("b", None)], dependency_map=dm)),81 [("b", None), ("c", None), ("d", None)])82 # Expansion with two groups -- each group is handled independently.83 self.assertEqual(list(add_extra_dependencies([("b", None),84 (None, "package"),85 ("c", None)], dependency_map=dm)),86 [("b", None), ("c", None), ("d", None),87 (None, "package"),88 ("c", None), ("d", None)])89 # Two groups, no duplicate dependencies in each group.90 self.assertEqual(list(add_extra_dependencies([("a", None), ("b", None),91 (None, "package"), (None, "install"),92 ("c", None), ("d", None)], dependency_map=dm)),93 [("a", None), ("b", None), ("c", None), ("d", None),94 (None, "package"), (None, "install"),95 ("c", None), ("d", None)])96if __name__ == '__main__':...

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 pytest-bdd 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