Пример #1
0
def test_input_argv():
    with TestAreaContext("stea_input_argv"):

        with open("config_file", "w") as f:
            f.write("{}: 2018-10-10 12:00:00\n".format(
                SteaInputKeys.CONFIG_DATE))
            f.write("{}: 1234\n".format(SteaInputKeys.PROJECT_ID))
            f.write("{}: 1\n".format(SteaInputKeys.PROJECT_VERSION))

            f.write("{}: \n".format(SteaInputKeys.ECL_PROFILES))
            f.write("   ID1: \n")
            f.write("      {}: FOPT\n".format(SteaInputKeys.ECL_KEY))
            f.write("   ID2: \n")
            f.write("      {}: FGPT\n".format(SteaInputKeys.ECL_KEY))
            f.write("{}: \n".format(SteaInputKeys.RESULTS))
            f.write("   - npv\n")

        with pytest.raises(IOError):
            stea_input = SteaInput(
                ["config_file", "--{}=CSV".format(SteaInputKeys.ECL_CASE)])

        case = create_case()
        case.fwrite()
        stea_input = SteaInput(
            ["config_file", "--{}=CSV".format(SteaInputKeys.ECL_CASE)])
Пример #2
0
    def test_request2(self):
        with TestAreaContext("stea_request"):
            case = create_case()
            case.fwrite()
            with open("config_file","w") as f:
                f.write("{}: 2018-10-10\n".format(SteaInputKeys.CONFIG_DATE))
                f.write("{}: abc100\n".format(SteaInputKeys.PROJECT_ID))
                f.write("{}: 1\n".format(SteaInputKeys.PROJECT_VERSION))

                f.write("{}: \n".format(SteaInputKeys.ECL_PROFILES))
                f.write("   ID1: \n")
                f.write("      {}: FOPT\n".format(SteaInputKeys.ECL_KEY))
                f.write("   ID2: \n")
                f.write("      {}: FGPT\n".format(SteaInputKeys.ECL_KEY))
                f.write("{}: \n".format(SteaInputKeys.RESULTS))
                f.write("   - npv\n")
                f.write("{}: {}\n".format(SteaInputKeys.ECL_CASE, "CSV"))

            stea_input = SteaInput("config_file")
            project = mock_project
            request = SteaRequest(stea_input, project)

            with self.assertRaises(KeyError):
                request.add_ecl_profile("ID1", "NO-SUCH-KEY")

            with self.assertRaises(KeyError):
                request.add_ecl_profile("INVALID-ID", "FOPT")
Пример #3
0
    def test_request1(self):
        with TestAreaContext("stea_request"):
            with open("config_file","w") as f:
                f.write("{}: 2018-10-10\n".format(SteaInputKeys.CONFIG_DATE))
                f.write("{}: abc100\n".format(SteaInputKeys.PROJECT_ID))
                f.write("{}: 1\n".format(SteaInputKeys.PROJECT_VERSION))

                f.write("{}: \n".format(SteaInputKeys.ECL_PROFILES))
                f.write("   ID1: \n")
                f.write("      {}: FOPT\n".format(SteaInputKeys.ECL_KEY))
                f.write("   ID2: \n")
                f.write("      {}: FGPT\n".format(SteaInputKeys.ECL_KEY))
                f.write("{}: \n".format(SteaInputKeys.RESULTS))
                f.write("   - npv\n")

            stea_input = SteaInput("config_file")
            project = mock_project

            case = create_case()
            case.fwrite()
            request = SteaRequest(stea_input, project)
            with self.assertRaises(KeyError):
                request.add_profile("no-such-id", 2018, [0,1,2])

            with self.assertRaises(ValueError):
                request.add_ecl_profile("ID1", "FOPT")
Пример #4
0
def test_config():
    with TestAreaContext("stea_main"):
        with pytest.raises(IOError):
            cnf = SteaInput(["File/does/not/exist"])

        # An invalid YAML file:
        with open("config_file", "w") as f:
            f.write("object:\n")
            f.write("    key: value :\n")

        with pytest.raises(ValueError):
            stea_main = SteaInput(["config_file"])

        with open("config_file", "w") as f:
            f.write("{}: 2018-10-10 12:00:00\n".format(
                SteaInputKeys.CONFIG_DATE))
            f.write("{}: 1234\n".format(SteaInputKeys.PROJECT_ID))
            f.write("{}: 1\n".format(SteaInputKeys.PROJECT_VERSION))

            f.write("{}: \n".format(SteaInputKeys.ECL_PROFILES))
            f.write("   ID1: \n")
            f.write("      {}: FOPT\n".format(SteaInputKeys.ECL_KEY))
            f.write("   ID2: \n")
            f.write("      {}: FGPT\n".format(SteaInputKeys.ECL_KEY))
            f.write("{}: \n".format(SteaInputKeys.RESULTS))
            f.write("   - npv\n")

        stea_input = SteaInput(["config_file"])
        assert stea_input.config_date == datetime.datetime(
            2018, 10, 10, 12, 0, 0)
        assert stea_input.project_id == 1234
        assert stea_input.project_version == 1
        assert 2 == len(stea_input.ecl_profiles)
        keys = [key[0] for key in stea_input.ecl_profiles]
        assert "ID1" in keys
        assert "ID2" in keys

        with open("config_file", "w") as f:
            f.write("{}: No-not-a-date".format(SteaInputKeys.CONFIG_DATE))

        with pytest.raises(ValueError):
            stea_main = SteaInput(["config_file"])
Пример #5
0
    def test_config(self):
        with TestAreaContext("stea_main"):
            with self.assertRaises(IOError):
                cnf = SteaInput("File/does/not/exist")

            # An invalid YAML file:
            with open("config_file","w") as f:
                f.write("object:\n")
                f.write("    key: value :\n")

            with self.assertRaises(ValueError):
                stea_main = SteaInput("config_file")


            with open("config_file","w") as f:
                f.write("{}: 2018-10-10\n".format(SteaInputKeys.CONFIG_DATE))
                f.write("{}: abc100\n".format(SteaInputKeys.PROJECT_ID))
                f.write("{}: 1\n".format(SteaInputKeys.PROJECT_VERSION))

                f.write("{}: \n".format(SteaInputKeys.ECL_PROFILES))
                f.write("   ID1: \n")
                f.write("      {}: FOPT\n".format(SteaInputKeys.ECL_KEY))
                f.write("   ID2: \n")
                f.write("      {}: FGPT\n".format(SteaInputKeys.ECL_KEY))
                f.write("{}: \n".format(SteaInputKeys.RESULTS))
                f.write("   - npv\n")

            stea_input = SteaInput("config_file")
            self.assertEqual(stea_input.config_date, datetime.datetime(2018,10,10))
            self.assertEqual(stea_input.project_id, "abc100")
            self.assertEqual(stea_input.project_version, 1)
            self.assertEqual(2, len(stea_input.ecl_profiles))
            self.assertIn("ID1", stea_input.ecl_profiles)
            self.assertIn("ID2", stea_input.ecl_profiles)

            with open("config_file","w") as f:
                f.write("{}: No-not-a-date".format(SteaInputKeys.CONFIG_DATE))

            with self.assertRaises(ValueError):
                stea_main = SteaInput("config_file")
Пример #6
0
    def test_results(self):
        with TestAreaContext("stea_request"):
            case = create_case()
            case.fwrite()
            with open("config_file","w") as f:
                f.write("{}: {}\n".format(SteaInputKeys.CONFIG_DATE, self.config_date))
                f.write("{}: {}\n".format(SteaInputKeys.PROJECT_ID, self.project_id))
                f.write("{}: {}\n".format(SteaInputKeys.PROJECT_VERSION, self.project_version))
                f.write("{}: \n".format(SteaInputKeys.ECL_PROFILES))
                f.write("   {}: \n".format(self.fopt_profile_id))
                f.write("      {}: FOPT\n".format(SteaInputKeys.ECL_KEY))
                f.write("{}: {}\n".format(SteaInputKeys.SERVER, test_server))
                f.write("{}: \n".format(SteaInputKeys.RESULTS))
                f.write("   - NPV\n")
                f.write("{}: {}\n".format(SteaInputKeys.ECL_CASE, "CSV"))

            stea_input = SteaInput("config_file")
Пример #7
0
def test_calculate(set_up):
    with TestAreaContext("stea_request"):
        case = create_case()
        case.fwrite()
        with open("config_file", "w") as f:
            f.write("{}: {}\n".format(SteaInputKeys.CONFIG_DATE,
                                      set_up.config_date))
            f.write("{}: {}\n".format(SteaInputKeys.PROJECT_ID,
                                      set_up.project_id))
            f.write("{}: {}\n".format(SteaInputKeys.PROJECT_VERSION,
                                      set_up.project_version))
            f.write("{}: \n".format(SteaInputKeys.ECL_PROFILES))
            f.write("   {}: \n".format(set_up.fopt_profile_id))
            f.write("      {}: FOPT\n".format(SteaInputKeys.ECL_KEY))
            f.write("{}: {}\n".format(SteaInputKeys.SERVER, test_server))
            f.write("{}: \n".format(SteaInputKeys.RESULTS))
            f.write("   - NPV\n")
            f.write("{}: {}\n".format(SteaInputKeys.ECL_CASE, "CSV"))

        stea_input = SteaInput(["config_file"])
        results = calculate(stea_input)
        for res, value in results.results(SteaKeys.CORPORATE).items():
            print("DBG_TEST {}, {}".format(res, value))