Example #1
0
 def test_return_true_when_package_installed(self):
   stdout = dedent("""
   Package: python3
   Status: install ok installed
   Priority: optional
   Section: python
   Installed-Size: 89
   Maintainer: Matthias Klose <*****@*****.**>
   Architecture: amd64
   Multi-Arch: allowed
   Source: python3-defaults
   Version: 3.9.2-3
   Replaces: python3-minimal (<< 3.1.2-2)
   Provides: python3-profiler
   Depends: python3.9 (>= 3.9.2-0~), libpython3-stdlib (= 3.9.2-3)
   Pre-Depends: python3-minimal (= 3.9.2-3)
   Suggests: python3-doc (>= 3.9.2-3), python3-tk (>= 3.9.2-0~),
   Description: interactive high-level object-oriented languag
    Python, the high-level, interactive object oriented language,
    includes an extensive class library with lots of goodies for
    network programming, system administration, sounds and graphics.
    .
    This package is a dependency package, which depends on Debian's default
    Python 3 version (currently v3.9).
   Homepage: https://www.python.org/
   Cnf-Extra-Commands: python
   Cnf-Priority-Bonus: 5""").strip()
   g = None
   a = Apt(_mock_run(['dpkg', '-s', 'python3'],
                     CompletedProcess(stdout, 'stderr', 0, 'cmd')))
   assert a.get_package_version(g, 'python3') == '3.9.2-3'
Example #2
0
 def test_return_empty_list_if_package_not_available(self):
   g = None
   a = Apt(_mock_run(
     ['apt-cache', 'madison', 'cloud-init'],
     CompletedProcess(
       'N: Unable to locate package cloud-init', '', 1, 'cmd')))
   assert a.list_available_versions(g, 'cloud-init') == set()
Example #3
0
 def test_return_empty_string_when_version_not_detected(self):
   stdout = dedent("""
   Package: python3
   Cnf-Priority-Bonus: 5""").strip()
   g = None
   a = Apt(_mock_run(['dpkg', '-s', 'python3'],
                     CompletedProcess(stdout, 'stderr', 0, 'cmd')))
   assert a.get_package_version(g, 'python3') == ''
Example #4
0
  def test_skip_lines_from_madison_with_unexpected_syntax(self):
    g = None
    stdout = '\n'.join([
      'cloud-init | 21.3-1-g6803368d-0ubuntu1~20.04.3 | repo',
      'cloud-init | extra bar | repo | not-recognized',
      'cloud-init | missing bar',
      'no bar',
    ])

    a = Apt(_mock_run(['apt-cache', 'madison', 'cloud-init'],
                      CompletedProcess(stdout, '', 0, 'cmd')))
    assert a.list_available_versions(g, 'cloud-init') == {
      '21.3-1-g6803368d-0ubuntu1~20.04.3'}
Example #5
0
  def test_return_versions_if_available(self):
    g = None
    stdout = '\n'.join([
      'cloud-init | 21.3-1-g6803368d-0ubuntu1~20.04.3 | repo',
      'cloud-init | 20.1-10-g71af48df-0ubuntu5 | repo',
      'cloud-init | 0.7.5-0ubuntu1.23 | repo',
    ])

    a = Apt(_mock_run(['apt-cache', 'madison', 'cloud-init'],
                      CompletedProcess(stdout, '', 0, 'cmd')))
    assert a.list_available_versions(g, 'cloud-init') == {
      '21.3-1-g6803368d-0ubuntu1~20.04.3',
      '20.1-10-g71af48df-0ubuntu5',
      '0.7.5-0ubuntu1.23'}
 def test_return_completed_process_when_success(self):
     cmd = 'echo abc123'
     result = run(_make_local_guestfs(), cmd)
     assert result == CompletedProcess('abc123\n', '', 0, cmd)
 def test_capture_output_when_non_zero_return(self):
     cmd = 'printf content; printf err > /dev/stderr; exit 1'
     result = run(_make_local_guestfs(), cmd, raiseOnError=False)
     assert result == CompletedProcess('content', 'err', 1, cmd)
 def test_escape_array_members(self):
     result = run(_make_local_guestfs(), ['echo', 'hello', '; ls *'],
                  raiseOnError=False)
     assert result == CompletedProcess('hello ; ls *\n', '', 0,
                                       "echo hello '; ls *'")
 def test_support_array_args(self):
     result = run(_make_local_guestfs(), ['echo', 'hi'], raiseOnError=False)
     assert result == CompletedProcess('hi\n', '', 0, 'echo hi')
 def test_support_positive_code(self):
     cmd = 'exit 100'
     result = run(_make_local_guestfs(), cmd, raiseOnError=False)
     assert result == CompletedProcess('', '', 100, cmd)
 def test_capture_stderr(self):
     cmd = 'echo error msg > /dev/stderr'
     result = run(_make_local_guestfs(), cmd, raiseOnError=False)
     assert result == CompletedProcess('', 'error msg\n', 0, cmd)
 def test_capture_stdout(self):
     cmd = 'echo abc123'
     result = run(_make_local_guestfs(), cmd, raiseOnError=False)
     assert result == CompletedProcess('abc123\n', '', 0, cmd)
Example #13
0
 def test_return_empty_string_when_package_not_installed(self):
   g = None
   a = Apt(_mock_run(['dpkg', '-s', 'cloud-init'],
                     CompletedProcess('stdout', 'stderr', 1, 'cmd')))
   assert a.get_package_version(g, 'cloud-init') == ''
Example #14
0
def test_support_array_args():
    result = run(_make_local_guestfs(), ['echo', 'hi'])
    assert result == CompletedProcess('hi\n', '', 0, 'echo hi')
Example #15
0
def test_support_positive_code():
    cmd = 'exit 100'
    result = run(_make_local_guestfs(), cmd)
    assert result == CompletedProcess('', '', 100, cmd)
Example #16
0
def test_capture_stdout():
    cmd = 'echo abc123'
    result = run(_make_local_guestfs(), cmd)
    assert result == CompletedProcess('abc123\n', '', 0, cmd)