def test_serialize():
    """Should be serialized"""
    arp = AutoRegressionParameters(country="United States",
                                   data="/path/to/data.csv")
    data = arp.serialize()
    expected = {"country": "united_states", "data": "/path/to/data.csv"}
    assert data == expected
def test_deserialize():
    """Param data should be deserialized as AutoRegressionParameters instance"""
    param = {"country": "United States", "data": "/path/to/data.csv"}
    ari = AutoRegressionParameters.deserialize(param)
    assert isinstance(ari, AutoRegressionParameters)
    assert ari.country == "United States"
    assert ari.data == "/path/to/data.csv"
    assert ari.name == "united_states"
def test_show_results(capsys):
    """Should print jobs to std.out"""
    arc = AutoRegressionConfiguration()
    job1 = AutoRegressionParameters(country="AAA", data="AA.csv")
    arc.add_job(job1)

    arc.show_jobs()

    captured = capsys.readouterr()
    assert "aaa" in captured.out
def test_serialize_jobs():
    """Should serialize a series of jobs"""
    arc = AutoRegressionConfiguration()
    job1 = AutoRegressionParameters(country="A", data="A.csv")
    arc.add_job(job1)

    job2 = AutoRegressionParameters(country="B", data="B.csv")
    arc.add_job(job2)

    directory = os.path.join(tempfile.gettempdir(), "jade-unit-test-dir")
    os.makedirs(directory, exist_ok=True)
    arc.serialize_jobs(directory)

    serialized_job1 = os.path.join(directory, "a.json")
    assert os.path.exists(serialized_job1)

    serialized_job2 = os.path.join(directory, "b.json")
    assert os.path.exists(serialized_job2)

    shutil.rmtree(directory)
Esempio n. 5
0
def test_get_available_parameters(test_data_dir):
    """Should get 12 jobs"""
    base_directory = os.path.join(test_data_dir, "demo")
    ari = AutoRegressionInputs(base_directory)
    ari.get_available_parameters()
    assert len(ari._parameters) == 3

    param = AutoRegressionParameters(country="United States", data="data.csv")
    key = param.name

    assert key in ari._parameters
def test_serialize_for_execution():
    """Serialize config data for efficient execution"""
    arc = AutoRegressionConfiguration()
    job1 = AutoRegressionParameters(country="AA", data="AA.csv")
    arc.add_job(job1)

    job2 = AutoRegressionParameters(country="BB", data="BB.csv")
    arc.add_job(job2)

    # Serialize for execution
    scratch_dir = os.path.join(
        tempfile.gettempdir(),
        "jade-unit-test-scratch-dir",
    )
    os.makedirs(scratch_dir, exist_ok=True)
    arc.serialize_for_execution(scratch_dir)

    config_file = os.path.join(scratch_dir, "config.json")
    assert os.path.exists(config_file)

    shutil.rmtree(scratch_dir)
Esempio n. 7
0
    def get_available_parameters(self):
        """Collect all available auto-regression jobs"""
        inputs_file = os.path.join(self._base_directory, self.INPUTS_FILE)
        inputs = load_data(inputs_file)

        for param in inputs:
            job = AutoRegressionParameters(country=param["country"],
                                           data=os.path.join(
                                               self._base_directory,
                                               param["data"]))

            self._parameters[job.name] = job
def test_init():
    """Should return an AutoRegressionParameters instance with desired properties"""
    arp = AutoRegressionParameters(country="United States",
                                   data="/path/to/data.csv")
    assert arp.name == "united_states"
def test_name():
    """Should create a name for job"""
    arp = AutoRegressionParameters(country="United States",
                                   data="/path/to/data.csv")
    assert arp.name == "united_states"