/yotta/test/test_hg_access.py

https://gitlab.com/b_perraudin_catie/yotta · Python · 72 lines · 41 code · 15 blank · 16 comment · 2 complexity · 536957c15e4af3299681d456e569fda7 MD5 · raw file

  1. #!/usr/bin/env python
  2. # Copyright 2014 ARM Limited
  3. #
  4. # Licensed under the Apache License, Version 2.0
  5. # See LICENSE file for details.
  6. # standard library modules, , ,
  7. import unittest
  8. import os
  9. from collections import namedtuple
  10. # hgapi, pip install hgapi, python api to hg command, "Do whatever you want,
  11. # but don't blame me"
  12. import hgapi
  13. # hg_access, , access to components available from hg repositories, internal
  14. from yotta.lib import hg_access
  15. # fsutils, , misc filesystem utils, internal
  16. from yotta.lib import fsutils
  17. # version, , represent versions and specifications, internal
  18. from yotta.lib import version
  19. # sourceparse, , parse version source urls, internal
  20. from yotta.lib import sourceparse
  21. # install, , install components, internal
  22. from yotta import install
  23. Test_Name = 'hg-testing-dummy'
  24. Test_Repo = "hg+ssh://hg@bitbucket.org/autopulated/hg-testing-dummy"
  25. Test_Repo_With_Spec = "hg+ssh://hg@bitbucket.org/autopulated/hg-testing-dummy#0.0.2"
  26. Test_Deps_Name = 'hg-access-testing'
  27. Test_Deps_Target = 'x86-osx-native,*'
  28. def ensureHGConfig():
  29. # test if we have a hg user set up, if not we need to set one
  30. info = hgapi.Repo.command(".", os.environ, "showconfig")
  31. if info.find("ui.username") == -1:
  32. # hg doesn't provide a way to set the username from the command line.
  33. # The HGUSER environment variable can be used for that purpose.
  34. os.environ['HGUSER'] = 'Yotta Test <test@yottabuild.org>'
  35. class TestHGAccess(unittest.TestCase):
  36. def setUp(self):
  37. ensureHGConfig()
  38. vs = sourceparse.parseSourceURL(Test_Repo)
  39. self.remote_component = hg_access.HGComponent.createFromSource(vs, Test_Name)
  40. self.assertTrue(self.remote_component)
  41. self.working_copy = self.remote_component.clone()
  42. self.assertTrue(self.working_copy)
  43. def tearDown(self):
  44. fsutils.rmRf(self.working_copy.directory)
  45. def test_installDeps(self):
  46. Args = namedtuple('Args', ['component', 'target', 'act_globally', 'install_linked', 'install_test_deps', 'config'])
  47. install.installComponent(Args(Test_Deps_Name, Test_Deps_Target, False, False, 'own', {}))
  48. def test_availableVersions(self):
  49. versions = self.working_copy.availableVersions()
  50. self.assertIn(version.Version('v0.0.1'), versions)
  51. def test_versionSpec(self):
  52. vs = sourceparse.parseSourceURL(Test_Repo_With_Spec)
  53. spec = hg_access.HGComponent.createFromSource(vs, Test_Name).versionSpec()
  54. v = spec.select(self.working_copy.availableVersions())
  55. self.assertTrue(v)
  56. if __name__ == '__main__':
  57. unittest.main()