Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #31 from OneBusAway/2to3
Browse files Browse the repository at this point in the history
Python 2 -> 3, end to end tests, and CI
  • Loading branch information
aaronbrethorst authored Mar 19, 2024
2 parents 728df49 + 09897ec commit 3fa52f4
Show file tree
Hide file tree
Showing 10 changed files with 2,756 additions and 39 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: End-to-End Tests

on:
push:
branches: [ main ]
pull_request:

jobs:
run-e2e-tests:
runs-on: ubuntu-latest

steps:
- name: Check out repository code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: Run End-to-End tests
run: python test_e2e.py
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
__pycache__
./regions.xml
./regions.json
./regions-v3.xml
./regions-v3.json
tests/tmp/*.json
tests/tmp/*.xml
41 changes: 41 additions & 0 deletions test_e2e.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python

import subprocess
import unittest
import os

class TestEndToEnd(unittest.TestCase):
@staticmethod
def read_file_as_string(file_path):
# Determine the directory of the current script (test_e2e.py)
current_script_directory = os.path.dirname(os.path.realpath(__file__))

# Construct an absolute path by combining the script directory with the relative file path
absolute_file_path = os.path.join(current_script_directory, file_path)

with open(absolute_file_path, 'r', encoding='utf-8') as file:
return file.read()

def test_update_regions_output(self):
command = ["python", "update_regions.py", "--input-file", "./tests/fixtures/server_directory.csv", "--output-dir", "./tests/tmp", "--pretty"]
_ = subprocess.run(command, capture_output=True, text=True)

regions_xml_fixture = self.read_file_as_string('tests/fixtures/regions.xml')
regions_xml_output = self.read_file_as_string('tests/tmp/regions.xml')
self.assertEqual(regions_xml_fixture, regions_xml_output, "regions.xml should be identical")

regions_xml_v3_fixture = self.read_file_as_string('tests/fixtures/regions-v3.xml')
regions_xml_v3_output = self.read_file_as_string('tests/tmp/regions-v3.xml')
self.assertEqual(regions_xml_v3_fixture, regions_xml_v3_output, "regions-v3.xml should be identical")

regions_json_fixture = self.read_file_as_string('tests/fixtures/regions.json')
regions_json_output = self.read_file_as_string('tests/tmp/regions.json')
self.assertEqual(regions_json_fixture, regions_json_output, "regions.json should be identical")

regions_json_v3_fixture = self.read_file_as_string('tests/fixtures/regions-v3.json')
regions_json_v3_output = self.read_file_as_string('tests/tmp/regions-v3.json')
self.assertEqual(regions_json_v3_fixture, regions_json_v3_output, "regions-v3.json should be identical")

# This allows the test to be run from the command line
if __name__ == '__main__':
unittest.main()
Loading

0 comments on commit 3fa52f4

Please sign in to comment.