Exemple #1
0
    def test_from_json_empty_file(self):
        # given
        test_file = os.path.join(self.test_data, "empty.json")

        # when
        with pytest.raises(json.decoder.JSONDecodeError) as execinfo:
            from_json_file(test_file)

        # then
        assert "Expecting value" in str(execinfo.value)
Exemple #2
0
    def test_from_json_bad_file(self):
        # given
        # intentional typo
        test_file = os.path.join(self.test_data, "idxx-e-gpl-rh6-36.json")

        # when
        with pytest.raises(FileNotFoundError) as execinfo:
            from_json_file(test_file)

        # then
        assert "No such file or directory" in str(execinfo.value)
Exemple #3
0
    def test_diff_manual_edits(self):
        """ Use test_data json files, same index, one with manual edits."""

        # when
        remote_idx = from_json_file(os.path.join(self.test_data,
                                                 "idx-e-gpl-rh6-36.json"))
        local_idx = from_json_file(os.path.join(self.test_data,
                                                "idx-e-gpl-rh6-36-edit.json"))
        diff = index_diff(local_idx, remote_idx)

        # then
        assert diff['missing']
        assert "psycopg2-2.7.3.2-1.egg" in diff['missing'].keys()
Exemple #4
0
    def test_gen_full_index(self):
        # given
        BASE_URL = "https://packages.enthought.com"  # intentional typo
        REPOS = ("gpl", "free")
        ORG = ("enthought", )
        PLATS = ("rh6-x86_64", "osx-x86_64")
        VERS = ("cp27", "cp35", "cp36")

        ORG_REPOS = tuple("/".join(t) for t in product(ORG, REPOS))

        _, out_path = tempfile.mkstemp(suffix=".json")

        # when
        gen_full_index(BASE_URL, ORG_REPOS, PLATS, VERS, out_path)

        # raises JSONDecodeError if file is empty
        idx = from_json_file(out_path)

        # then
        assert os.path.exists(out_path)
        assert os.path.isfile(out_path)
        assert idx

        # Make sure a package from each repo exists
        # enthought/free: alabaster-0.7.9-1
        # enthought/gpl: Qt-4.8.7-7
        assert "alabaster-0.7.9-1.egg" in idx.keys()
        assert "Qt-4.8.7-7.egg" in idx.keys()
Exemple #5
0
    def test_merge_json(self):
        # given
        indices = [
            "idx-e-free-rh6-x86_64-36.json", "idx-e-gpl-rh6-x86_64-36.json",
            "idx-e-lgpl-rh6-x86_64-36.json"
        ]
        paths = [os.path.join(self.test_data, idx) for idx in indices]

        # when
        _, out_path = tempfile.mkstemp(suffix=".json")
        merge_json(paths, out_path)
        full_idx = from_json_file(out_path)

        # then
        for path in paths:
            idx = from_json_file(path)
            assert set(idx).issubset(set(full_idx))
Exemple #6
0
    def test_from_json(self):
        # given
        test_file = os.path.join(self.test_data, "idx-e-gpl-rh6-36.json")

        # when
        idx = from_json_file(test_file)

        # then
        assert isinstance(idx, dict)
        assert idx
Exemple #7
0
    def test_read_formatted_json(self):
        """ Test reading vs-code auto json formatting."""
        # given
        test_file = os.path.join(self.test_data, "test-formatted-index.json")

        # when
        idx = from_json_file(test_file)

        # then
        assert isinstance(idx, dict)
        assert idx
Exemple #8
0
    def test_diff_local_empty(self):
        # given

        # when
        local_idx = {}
        remote_idx = from_json_file(os.path.join(self.test_data,
                                                 "idx-e-gpl-rh6-36.json"))

        diff = index_diff(local_idx, remote_idx)

        # then
        assert diff['missing']
        assert diff['missing'].keys() == remote_idx.keys()
Exemple #9
0
    def test_to_from_json_round_trip(self):
        # given
        BASE_URL = "https://packages.enthought.com"
        REPO = "gpl"
        ORG = "enthought"
        PLAT = "rh6-x86_64"
        VER = "cp27"

        # when
        idx_from_brood = get_index(url=BASE_URL,
                                   org=ORG,
                                   repo=REPO,
                                   plat=PLAT,
                                   pyver=VER)

        _, path = tempfile.mkstemp(suffix=".json")
        to_json_file(idx_from_brood, path)

        idx_from_file = from_json_file(path)

        # then
        assert idx_from_brood == idx_from_file