
import pytest
import toolaudit
import yaml


def test_simple_audit(capsys):
    """
    Check simple audit gives the expected output
    """
    app = toolaudit.application.ToolauditApp()
    try:
        app.run(kitlist_file='test/example.yaml')
    except SystemExit:
        pass
    out, err = capsys.readouterr()
    returned_yaml = yaml.load(out)
    assert returned_yaml['tools'][0]['checksum'] == '9c3bb3efa8095f36aafd9bf3a698efe439505021'


import pytest
import toolaudit
import yaml


def test_simple_audit(capsys, monkeypatch):
    """
    Check simple audit gives the expected output
    """
    def mockreturn(path):
        return '9c3bb3efa8095f36aafd9bf3a698efe439505021'
    monkeypatch.setattr(toolaudit.readers, 'sha1_file', mockreturn)
    app = toolaudit.application.ToolauditApp()
    try:
        app.run(kitlist_file='test/example.yaml')
    except SystemExit:
        pass
    out, err = capsys.readouterr()
    returned_yaml = yaml.load(out)
    assert returned_yaml['tools'][0]['checksum'] == '9c3bb3efa8095f36aafd9bf3a698efe439505021'

Use mocking to fix the result of hashing files
Use mocking to fix the result of hashing files

  
  import pytest
  import toolaudit
  import yaml
  
  
- def test_simple_audit(capsys):
+ def test_simple_audit(capsys, monkeypatch):
      """
      Check simple audit gives the expected output
      """
+     def mockreturn(path):
+         return '9c3bb3efa8095f36aafd9bf3a698efe439505021'
+     monkeypatch.setattr(toolaudit.readers, 'sha1_file', mockreturn)
      app = toolaudit.application.ToolauditApp()
      try:
          app.run(kitlist_file='test/example.yaml')
      except SystemExit:
          pass
      out, err = capsys.readouterr()
      returned_yaml = yaml.load(out)
      assert returned_yaml['tools'][0]['checksum'] == '9c3bb3efa8095f36aafd9bf3a698efe439505021'
  
Use mocking to fix the result of hashing files
## Code Before:

import pytest
import toolaudit
import yaml


def test_simple_audit(capsys):
    """
    Check simple audit gives the expected output
    """
    app = toolaudit.application.ToolauditApp()
    try:
        app.run(kitlist_file='test/example.yaml')
    except SystemExit:
        pass
    out, err = capsys.readouterr()
    returned_yaml = yaml.load(out)
    assert returned_yaml['tools'][0]['checksum'] == '9c3bb3efa8095f36aafd9bf3a698efe439505021'

## Instruction:
Use mocking to fix the result of hashing files
## Code After:

import pytest
import toolaudit
import yaml


def test_simple_audit(capsys, monkeypatch):
    """
    Check simple audit gives the expected output
    """
    def mockreturn(path):
        return '9c3bb3efa8095f36aafd9bf3a698efe439505021'
    monkeypatch.setattr(toolaudit.readers, 'sha1_file', mockreturn)
    app = toolaudit.application.ToolauditApp()
    try:
        app.run(kitlist_file='test/example.yaml')
    except SystemExit:
        pass
    out, err = capsys.readouterr()
    returned_yaml = yaml.load(out)
    assert returned_yaml['tools'][0]['checksum'] == '9c3bb3efa8095f36aafd9bf3a698efe439505021'
