From c8e76787c18e2339bb6af33d934a0e568cbcc283 Mon Sep 17 00:00:00 2001 From: Qiusheng Wu Date: Sat, 10 Jul 2021 14:18:05 -0400 Subject: [PATCH] Added tests #567 --- .github/workflows/integration.yml | 105 ------------------------------ .github/workflows/ok-to-test.yml | 34 ---------- tests/test_geemap.py | 96 ++++++++++++--------------- 3 files changed, 43 insertions(+), 192 deletions(-) delete mode 100644 .github/workflows/integration.yml delete mode 100644 .github/workflows/ok-to-test.yml diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml deleted file mode 100644 index 47d9ecffd6..0000000000 --- a/.github/workflows/integration.yml +++ /dev/null @@ -1,105 +0,0 @@ -# Run secret-dependent integration tests only after /ok-to-test approval -on: - pull_request: - repository_dispatch: - types: [ok-to-test-command] - -name: Integration tests - -jobs: - # Branch-based pull request - integration-trusted: - runs-on: ubuntu-latest - if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository - steps: - - name: Branch based PR checkout - uses: actions/checkout@v2 - - # - - # Repo owner has commented /ok-to-test on a (fork-based) pull request - integration-fork: - runs-on: ubuntu-latest - if: github.event_name == 'repository_dispatch' && - github.event.client_payload.slash_command.sha != '' && - contains(github.event.client_payload.pull_request.head.sha, github.event.client_payload.slash_command.sha) - steps: - # Check out merge commit - - name: Fork based /ok-to-test checkout - uses: actions/checkout@v2 - with: - ref: "refs/pull/${{ github.event.client_payload.pull_request.number }}/merge" - - # - - # runs-on: ${{ matrix.config.os }} - # name: ${{ matrix.config.os }} (${{ matrix.config.py }}) - # strategy: - # fail-fast: false - # matrix: - # config: - # - { os: windows-latest, py: "3.7" } - # - { os: macOS-latest, py: "3.7" } - # - { os: ubuntu-latest, py: "3.6" } - # - { os: ubuntu-latest, py: "3.7" } - # - { os: ubuntu-latest, py: "3.8" } - - # env: - # SDKROOT: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk - # steps: - # - name: CHECKOUT CODE - # uses: actions/checkout@v2 - # - name: SETUP PYTHON - # uses: actions/setup-python@v1 - # with: - # python-version: ${{ matrix.config.py }} - # - name: Install dependencies - # run: | - # python -m pip install --upgrade pip - # pip install --user --no-cache-dir Cython - # pip install --user -r requirements.txt - # pip install --user -r requirements_dev.txt - # - name: LOAD EE CREDENTIALS - # run: python ./.github/ee_token.py - # env: - # EARTHENGINE_TOKEN: ${{ secrets.EARTHENGINE_TOKEN }} - # - name: GEEMAP-TEST - # run: | - # python -m unittest discover tests/ - - - run: | - echo "Integration tests... success! ;-)" - - # Update check run called "integration-fork" - - uses: actions/github-script@v1 - id: update-check-run - if: ${{ always() }} - env: - number: ${{ github.event.client_payload.pull_request.number }} - job: ${{ github.job }} - # Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run - conclusion: ${{ job.status }} - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const { data: pull } = await github.pulls.get({ - ...context.repo, - pull_number: process.env.number - }); - const ref = pull.head.sha; - - const { data: checks } = await github.checks.listForRef({ - ...context.repo, - ref - }); - - const check = checks.check_runs.filter(c => c.name === process.env.job); - - const { data: result } = await github.checks.update({ - ...context.repo, - check_run_id: check[0].id, - status: 'completed', - conclusion: process.env.conclusion - }); - - return result; diff --git a/.github/workflows/ok-to-test.yml b/.github/workflows/ok-to-test.yml deleted file mode 100644 index 0d7306783d..0000000000 --- a/.github/workflows/ok-to-test.yml +++ /dev/null @@ -1,34 +0,0 @@ -# If someone with write access comments "/ok-to-test" on a pull request, emit a repository_dispatch event -name: Label - -on: - issue_comment: - types: [created] - -jobs: - ok-to-test: - runs-on: ubuntu-latest - steps: - # Generate a GitHub App installation access token from an App ID and private key - # To create a new GitHub App: - # https://developer.github.com/apps/building-github-apps/creating-a-github-app/ - # See app.yml for an example app manifest - # - name: Generate token - # id: generate_token - # uses: tibdex/github-app-token@v1 - # with: - # app_id: ${{ secrets.APP_ID }} - # private_key: ${{ secrets.PRIVATE_KEY }} - - - name: Slash Command Dispatch - uses: peter-evans/slash-command-dispatch@v1 - env: - TOKEN: ${{ steps.generate_token.outputs.token }} - with: - # token: ${{ env.TOKEN }} # GitHub App installation access token - token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} # PAT or OAuth token will also work - # reaction-token: ${{ secrets.GITHUB_TOKEN }} - issue-type: pull-request - commands: ok-to-test - named-args: true - permission: write diff --git a/tests/test_geemap.py b/tests/test_geemap.py index 81cece7b92..64460efc5c 100644 --- a/tests/test_geemap.py +++ b/tests/test_geemap.py @@ -20,61 +20,51 @@ def setUp(self): def tearDown(self): """Tear down test fixtures, if any.""" - # def test_001_default_settings(self): - # """Test the default settings returns an ImageCollection""" - # sentCollection = sentinel2_timeseries() - # self.assertIsInstance(sentCollection, ee.imagecollection.ImageCollection) + def test_001_default_settings(self): + """Test the default settings returns an ImageCollection""" + sentCollection = sentinel2_timeseries() + self.assertIsInstance(sentCollection, ee.imagecollection.ImageCollection) - # def test_002_good_years(self): - # start_year = [*range(2015, 2020, 1)] - # end_year = 2020 - # for year in start_year: - # sentCollection = sentinel2_timeseries(start_year=year, end_year=end_year) - # self.assertIsInstance(sentCollection, ee.imagecollection.ImageCollection) + def test_002_good_years(self): + start_year = [*range(2015, 2020, 1)] + end_year = 2020 + for year in start_year: + sentCollection = sentinel2_timeseries(start_year=year, end_year=end_year) + self.assertIsInstance(sentCollection, ee.imagecollection.ImageCollection) - # def test_003_good_dates(self): - # start_date = "06-01" - # end_date = "12-01" - # sentCollection = sentinel2_timeseries(start_date=start_date, end_date=end_date) - # self.assertIsInstance(sentCollection, ee.imagecollection.ImageCollection) + def test_003_good_dates(self): + start_date = "06-01" + end_date = "12-01" + sentCollection = sentinel2_timeseries(start_date=start_date, end_date=end_date) + self.assertIsInstance(sentCollection, ee.imagecollection.ImageCollection) - # def test_004_bad_years(self): - # years = [[2014, 2020], [2015, 2021], [205, 2019], [2016, 202]] - # for start_year, end_year in years: - # sentCollection = sentinel2_timeseries( - # start_year=start_year, end_year=end_year - # ) - # self.assertNotIsInstance(sentCollection, ee.imagecollection.ImageCollection) + def test_004_bad_years(self): + years = [[2014, 2020], [2015, 2021], [205, 2019], [2016, 202]] + for start_year, end_year in years: + sentCollection = sentinel2_timeseries( + start_year=start_year, end_year=end_year + ) + self.assertNotIsInstance(sentCollection, ee.imagecollection.ImageCollection) - # def test_006_prior_years(self): - # years = [ - # [2016, 2015], - # [2017, 2015], - # [2018, 2015], - # [2019, 2015], - # [2018, 2016], - # [2019, 2017], - # ] - # for start_year, end_year in years: - # self.assertRaises( - # Exception, - # sentinel2_timeseries(start_year=start_year, end_year=end_year), - # ) + def test_006_prior_years(self): + years = [ + [2016, 2015], + [2017, 2015], + [2018, 2015], + [2019, 2015], + [2018, 2016], + [2019, 2017], + ] + for start_year, end_year in years: + self.assertRaises( + Exception, + sentinel2_timeseries(start_year=start_year, end_year=end_year), + ) - # def test_007_bad_dates(self): - # start_date = "06-01" - # end_date = "31-12" - # self.assertRaises( - # Exception, - # sentinel2_timeseries(start_date=start_date, end_date=end_date), - # ) - - # def test_command_line_interface(self): - # """Test the CLI.""" - # runner = CliRunner() - # result = runner.invoke(cli.main) - # assert result.exit_code == 0 - # assert 'geemap.cli.main' in result.output - # help_result = runner.invoke(cli.main, ['--help']) - # assert help_result.exit_code == 0 - # assert '--help Show this message and exit.' in help_result.output + def test_007_bad_dates(self): + start_date = "06-01" + end_date = "31-12" + self.assertRaises( + Exception, + sentinel2_timeseries(start_date=start_date, end_date=end_date), + )