Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/pr-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
name: PR Tests
permissions:
contents: read

on:
pull_request:
Expand All @@ -8,6 +10,8 @@ on:

jobs:
pr-tests:
uses: CitrineInformatics/common-gh-actions/.github/workflows/run-tests.yml@v1
uses: CitrineInformatics/common-gh-actions/.github/workflows/run-tests.yml@v1.1
with:
src: src/citrine
include_313: true
skip_38: false
Comment thread Fixed
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ wheels/
.installed.cfg
*.egg
MANIFEST
out/

# PyInstaller
# Usually these files are written by a python script from a template
Expand All @@ -46,6 +47,7 @@ coverage.xml
*.cover
.hypothesis/
.pytest_cache/
prof/

# Translations
*.mo
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
],
)
2 changes: 1 addition & 1 deletion src/citrine/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.23.0"
__version__ = "3.23.1"
3 changes: 1 addition & 2 deletions src/citrine/resources/file_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,7 @@ def _search_by_dataset_file_id(self,

@staticmethod
def _mime_type(file_path: Path):
# This string coercion is for supporting pathlib.Path objects in python < 3.8
mime_type = mimetypes.guess_type(str(file_path))[0]
mime_type, _ = mimetypes.guess_type(file_path)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer necessary.

if mime_type is None:
mime_type = "application/octet-stream"
return mime_type
Expand Down
39 changes: 24 additions & 15 deletions tests/resources/test_file_link.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
import platform
from typing import Collection
from uuid import uuid4, UUID

Expand Down Expand Up @@ -39,19 +40,27 @@ def valid_data() -> dict:
return FileLinkDataFactory(url='www.citrine.io', filename='materials.txt')


def test_mime_types(collection: FileCollection):
expected_xlsx = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
expected_xls = "application/vnd.ms-excel"
expected_txt = "text/plain"
expected_unk = "application/octet-stream"
expected_csv = "text/csv"

assert collection._mime_type(Path("asdf.xlsx")) == expected_xlsx
assert collection._mime_type(Path("asdf.XLSX")) == expected_xlsx
assert collection._mime_type(Path("asdf.xls")) == expected_xls
assert collection._mime_type(Path("asdf.TXT")) == expected_txt
assert collection._mime_type(Path("asdf.csv")) == expected_csv
assert collection._mime_type(Path("asdf.FAKE")) == expected_unk
@pytest.mark.parametrize(
("filename", "mimetype"),
[
pytest.param(
"asdf.xlsx",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
marks=pytest.mark.xfail(
platform.system() == "Windows",
reason="windows-latest test servers omit xlsx from their registry",
strict=True
)
),
("asdf.xls", "application/vnd.ms-excel"),
("asdf.XLS", "application/vnd.ms-excel"),
("asdf.TXT", "text/plain"),
("asdf.csv", "text/csv"),
("asdf.FAKE", "application/octet-stream"),
],
)
def test_mime_types(collection: FileCollection, filename, mimetype):
assert collection._mime_type(Path(filename)) == mimetype
Comment on lines +43 to +63
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test now parameterized. The xlsx tests were failing on windows-latest servers because xlsx was not in the build's registry; shouldn't be possible on a Windows box that can open xlsx files.

  • Marked xlsx as strict xfail on Windows, which will alert us if the test server config is updated
  • Moved the case-agnostic check over to xls instead, since that should always hold



def test_build_equivalence(collection, valid_data):
Expand All @@ -77,9 +86,9 @@ def test_string_representation(valid_data):

def test_from_path():
"""Test the string representation."""
path = '/some/path/with/file.txt'
path = Path.cwd() / 'some' / 'path' / 'with' / 'file.txt'
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generates a platform-agnostic absolute path, which is what was necessary for the test.

assert FileLink.from_path(path).filename == 'file.txt'
assert FileLink.from_path(Path(path)).url == Path(path).as_uri()
assert FileLink.from_path(str(path)).url == path.as_uri()
assert FileCollection._is_local_url(FileLink.from_path(path).url)


Expand Down
Loading