from unittest import TestCase

import create_minimal_image
from create_minimal_image import main

POPEN_COMMAND_LIST = ""


class CreateMinimalImageTest(TestCase):

    def setUp(self):
        global POPEN_COMMAND_LIST
        POPEN_COMMAND_LIST = ""
        create_minimal_image._run_popen_command = stubbed_run_popen_command

    def test_main_will_correctly_return_shared_objects_and_locations(self):
        self.maxDiff = None
        main("/usr/lib/jvm")
        self.assertEquals(POPEN_COMMAND_LIST, get_expected_popen_comands())


def stubbed_run_popen_command(command):
    global POPEN_COMMAND_LIST
    POPEN_COMMAND_LIST += " ".join(command) + "\n"
    try:
        with open("tests/fixtures/{0}.txt".format("_".join(command).replace("/", "_")), "r") as f:
            std_out = f.read()
        return std_out
    except:
        return ""


def get_expected_popen_comands():
    with open("tests/fixtures/expected_popen_commands.txt", "r") as f:
        expected_popen_commands = f.read()
    return expected_popen_commands

from unittest import TestCase

import create_minimal_image
from create_minimal_image import main

POPEN_COMMAND_LIST = []


class CreateMinimalImageTest(TestCase):

    def setUp(self):
        global POPEN_COMMAND_LIST
        POPEN_COMMAND_LIST = []
        create_minimal_image._run_popen_command = stubbed_run_popen_command

    def test_main_will_correctly_return_shared_objects_and_locations(self):
        self.maxDiff = None
        main("/usr/lib/jvm")
        self.assertEquals(POPEN_COMMAND_LIST, get_expected_popen_comands())


def stubbed_run_popen_command(command):
    POPEN_COMMAND_LIST.append(" ".join(command))
    try:
        with open("tests/fixtures/{0}.txt".format("_".join(command).replace("/", "_")), "r") as f:
            std_out = f.read()
        return std_out
    except:
        return ""


def get_expected_popen_comands():
    with open("tests/fixtures/expected_popen_commands.txt", "r") as f:
        expected_popen_commands = f.read().split("\n")
    return [command for command in expected_popen_commands if command != ""]

Revert "[TEST] refactor test to get it passing on Travis CI"
Revert "[TEST] refactor test to get it passing on Travis CI"

This reverts commit b92684d252e92a75115ce8617a15c107b5a34b09.

  from unittest import TestCase
  
  import create_minimal_image
  from create_minimal_image import main
  
- POPEN_COMMAND_LIST = ""
+ POPEN_COMMAND_LIST = []
  
  
  class CreateMinimalImageTest(TestCase):
  
      def setUp(self):
          global POPEN_COMMAND_LIST
-         POPEN_COMMAND_LIST = ""
+         POPEN_COMMAND_LIST = []
          create_minimal_image._run_popen_command = stubbed_run_popen_command
  
      def test_main_will_correctly_return_shared_objects_and_locations(self):
          self.maxDiff = None
          main("/usr/lib/jvm")
          self.assertEquals(POPEN_COMMAND_LIST, get_expected_popen_comands())
  
  
  def stubbed_run_popen_command(command):
-     global POPEN_COMMAND_LIST
-     POPEN_COMMAND_LIST += " ".join(command) + "\n"
+     POPEN_COMMAND_LIST.append(" ".join(command))
      try:
          with open("tests/fixtures/{0}.txt".format("_".join(command).replace("/", "_")), "r") as f:
              std_out = f.read()
          return std_out
      except:
          return ""
  
  
  def get_expected_popen_comands():
      with open("tests/fixtures/expected_popen_commands.txt", "r") as f:
-         expected_popen_commands = f.read()
+         expected_popen_commands = f.read().split("\n")
-     return expected_popen_commands
+     return [command for command in expected_popen_commands if command != ""]
  
Revert "[TEST] refactor test to get it passing on Travis CI"
## Code Before:
from unittest import TestCase

import create_minimal_image
from create_minimal_image import main

POPEN_COMMAND_LIST = ""


class CreateMinimalImageTest(TestCase):

    def setUp(self):
        global POPEN_COMMAND_LIST
        POPEN_COMMAND_LIST = ""
        create_minimal_image._run_popen_command = stubbed_run_popen_command

    def test_main_will_correctly_return_shared_objects_and_locations(self):
        self.maxDiff = None
        main("/usr/lib/jvm")
        self.assertEquals(POPEN_COMMAND_LIST, get_expected_popen_comands())


def stubbed_run_popen_command(command):
    global POPEN_COMMAND_LIST
    POPEN_COMMAND_LIST += " ".join(command) + "\n"
    try:
        with open("tests/fixtures/{0}.txt".format("_".join(command).replace("/", "_")), "r") as f:
            std_out = f.read()
        return std_out
    except:
        return ""


def get_expected_popen_comands():
    with open("tests/fixtures/expected_popen_commands.txt", "r") as f:
        expected_popen_commands = f.read()
    return expected_popen_commands

## Instruction:
Revert "[TEST] refactor test to get it passing on Travis CI"
## Code After:
from unittest import TestCase

import create_minimal_image
from create_minimal_image import main

POPEN_COMMAND_LIST = []


class CreateMinimalImageTest(TestCase):

    def setUp(self):
        global POPEN_COMMAND_LIST
        POPEN_COMMAND_LIST = []
        create_minimal_image._run_popen_command = stubbed_run_popen_command

    def test_main_will_correctly_return_shared_objects_and_locations(self):
        self.maxDiff = None
        main("/usr/lib/jvm")
        self.assertEquals(POPEN_COMMAND_LIST, get_expected_popen_comands())


def stubbed_run_popen_command(command):
    POPEN_COMMAND_LIST.append(" ".join(command))
    try:
        with open("tests/fixtures/{0}.txt".format("_".join(command).replace("/", "_")), "r") as f:
            std_out = f.read()
        return std_out
    except:
        return ""


def get_expected_popen_comands():
    with open("tests/fixtures/expected_popen_commands.txt", "r") as f:
        expected_popen_commands = f.read().split("\n")
    return [command for command in expected_popen_commands if command != ""]
