Scala subproject getting code coverage for outer project - scala

I have a project structure similar to the diagram below. The Bar project is my test code. I was wondering if I could get some code coverage against the src/main code FROM the Bar project code?
|-- Bar
| |-- build.sbt
| +-- src
| |-- main
| | |-- java
| | |-- resources
| | +-- scala
| | +-- Bar.scala
| +-- test
| |-- java
| +-- resources
|-- build.sbt
|-- project
| |-- Build.scala
|
+-- src
|-- main
| |-- java
| |-- resources
| +-- scala
| +-- Hello.scala
+-- test
|-- java
|-- resources
+-- scala
+-- HelloTest.scala

If the Bar project relies on methods in the src/main your Bar tests will cover them both

Related

Flutter Dependency Audit

So I have this fully created app that uses a few plugins. When the app is compiled in either iOS or Android I would like to audit and list which external libraries belong to which plugin.
I noticed some undesired libraries on my builds (the specific libraries do not matter) but tracking down which plugin is slow and time consuming (looking at platform code, plugin yaml files etc)
Is there a way to list the external dependencies related to each plugin on the console?
Thanks
In your command line, please run:
flutter pub deps
Output:
Dart SDK 2.7.0
Flutter SDK 1.12.13+hotfix.5
flutter_news 1.0.0+1
|-- build_runner 1.7.2
| |-- args...
| |-- async...
| |-- build 1.2.2
| | |-- analyzer...
| | |-- async...
| | |-- convert...
| | |-- crypto...
| | |-- glob...
| | |-- logging...
| | |-- meta...
| | '-- path...
| |-- build_config 0.4.1+1
| | |-- checked_yaml 1.0.2
| | | |-- json_annotation...
| | | |-- source_span...
| | | '-- yaml...
| | |-- json_annotation...
| | |-- meta...
| | |-- path...
| | |-- pubspec_parse...
| | '-- yaml...
| |-- build_daemon 2.1.2
| | |-- built_collection 4.3.0
| | | |-- collection...
| | | '-- quiver...
| | |-- built_value 7.0.0
| | | |-- built_collection...
| | | |-- collection...
| | | |-- fixnum 0.10.11
| | | '-- quiver...
| | |-- http_multi_server...
| | |-- logging...
...
For platform specific audits, you really have to review each plugin you're adding (at least for the 3rd party ones).
Android: How do I show dependencies tree in Android Studio?
Android: Look for the plugin's android/app/build.gradle file.
iOS: Look for the plugin's ios/Podfile.
More on:
https://dart.dev/tools/pub/cmd/pub-deps
Do you mind sharing your current pubspec.yaml file? So we could further help.

Spark: Select dynamic field name during XML load

While loading a path composed by XML files (+100.000 files) that contain almost the same structure, I need to create a dataframe mapping the XML tag fields to other field names (I'm using alias for this task). I'm using spark-xml library to achieve this goal.
However, there are some specific tag names that occur in some XML files and not in others (ICMS00, ICMS10, ICMS20, etc). Example:
<det nItem="1">
<imposto>
<ICMS>
<ICMS00>
<orig>0</orig>
<CST>00</CST>
<modBC>0</modBC>
<vBC>50.60</vBC>
<pICMS>12.00</pICMS>
<vICMS>6.07</vICMS>
</ICMS00>
</ICMS>
</imposto>
</det>
<det nItem="1">
<imposto>
<ICMS>
<ICMS20>
<orig>1</orig>
<CST>10</CST>
</ICMS20>
</ICMS>
</imposto>
</det>
The schema while loading without any modification is:
-- det: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- imposto: struct (nullable = true)
| | | |-- ICMS: struct (nullable = true)
| | | | |-- ICMS00: struct (nullable = true)
| | | | | |-- CST: long (nullable = true)
| | | | | |-- modBC: long (nullable = true)
| | | | | |-- orig: long (nullable = true)
| | | | | |-- pICMS: double (nullable = true)
| | | | | |-- vBC: double (nullable = true)
| | | | | |-- vICMS: double (nullable = true)
| | | | |-- ICMS20: struct (nullable = true)
| | | | | |-- CST: long (nullable = true)
| | | | | |-- orig: long (nullable = true)
I need a solution that maps the content of ICMS00 and ICMS20 to same column while creating a dataframe. However I could not find a solution similar to a select using regex or specifying the sub-tag without the fullpath.
The result schema should be similar to:
-- det: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- imposto: struct (nullable = true)
| | | |-- ICMS: struct (nullable = true)
| | | | |-- ICMS: struct (nullable = true) ###common tag name###
| | | | | |-- CST: long (nullable = true)
| | | | | |-- modBC: long (nullable = true)
| | | | | |-- orig: long (nullable = true)
| | | | | |-- pICMS: double (nullable = true)
| | | | | |-- vBC: double (nullable = true)
| | | | | |-- vICMS: double (nullable = true)
I already tried to change the schema before selecting fields:
# Transform variable ICMSXX fields to static ICMS
det_schema = df.schema['det'].json()
icms_schema = re.sub(r"ICMS([0-9])+", r"ICMS", det_schema)
det_schema_modified = StructField.fromJson(json.loads(icms_schema))
det_schema_modified.schema
# Explode det (item) and visualize the schema
df_itens = df.select(col('det').cast(det_schema_modified.dataType)).withColumn('det', explode(col('det')))
df_itens.select('det').printSchema()
However, it duplicates the schema and giver error when trying to select because of the duplicated field schema:
-- det: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- imposto: struct (nullable = true)
| | | |-- ICMS: struct (nullable = true)
| | | | |-- ICMS: struct (nullable = true)
| | | | | |-- CST: long (nullable = true)
| | | | | |-- modBC: long (nullable = true)
| | | | | |-- orig: long (nullable = true)
| | | | | |-- pICMS: double (nullable = true)
| | | | | |-- vBC: double (nullable = true)
| | | | | |-- vICMS: double (nullable = true)
| | | | |-- ICMS: struct (nullable = true)
| | | | | |-- CST: long (nullable = true)
| | | | | |-- orig: long (nullable = true)
My current code:
df = spark.read.format('com.databricks.spark.xml').options(rowTag='infNFe').load(file_location)
df_itens = df_itens.select(
col("det._nItem").alias("id"),
col("det.prod.cProd").alias("prod_cProd"),
col("det.prod.cEAN").alias("prod_cEAN"),
col("det.prod.NCM").alias("prod_NCM"),
col("det.imposto.ICMS.ICMS00.modBC").alias("ICMS_modBC"),
col("det.imposto.ICMS.ICMS00.vBC").alias("ICMS_vBC"),
col("det.imposto.ICMS.ICMS20.modBC").alias("ICMS_modBC"),
col("det.imposto.ICMS.ICMS20.vBC").alias("ICMS_vBC"),
etc.. for ICMS40, ICMS50, ICMS60, ...
Is there a way to select using regex or to handle these variable XML tag names while loading these files?
Something similar to:
df_itens.select(col("det.imposto.ICMS.ICMS*.modBC").alias("ICMS_modBC"))
or
df_itens.select(col("det.*.*.*.modBC").alias("ICMS_modBC"))

Problem loading resources in multiple builds

I'm a beginner learning scala/sbt. For multiple build projects, like this example:
|-- Bar
| |-- build.sbt
| +-- src
| |-- main
| | |-- java
| | |-- resources
| | | +-- config
| | | +-- app.properties
| | +-- scala
| | +-- Bar.scala
| +-- test
| |-- java
| +-- resources
|-- Foo
| |-- build.sbt
| +-- src
| |-- main
| | |-- java
| | |-- resources
| | +-- scala
| | +-- Foo.scala
| +-- test
| |-- java
| +-- resources
|-- build.sbt
|-- project
| |-- Build.scala
In Bar.scala, I tried to load files from resources but its not finding it:
val resourcesPath = getClass.getResource("config/app.properties")
println(resourcesPath.getPath)
>> Exception in thread "main" java.lang.NullPointerException

No code coverage in Babel Jest

I have a problem with code coverage. This the tests results :
[...]
24 tests passed (24 total in 9 test suites, run time 2.353s)
----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
----------|----------|----------|----------|----------|----------------|
All files | 100 | 100 | 100 | 100 | |
----------|----------|----------|----------|----------|----------------|
All reports generated
Process finished with exit code 0
All my tests succeed (count 73 expect). But no cover. I'm just testing normal node code. I use babel-jest, here you have the config in package.json :
"scripts": {
"test": "jest"
},
"jest": {
"collectCoverage": true,
"moduleFileExtensions": [
"js",
"json"
],
"scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
"testDirectoryName": "unit",
"testFileExtensions": [
"js"
],
"testPathDirs": [
"<rootDir>/tests/"
]
}
Here is my project architecture :
./
|-- app
| |-- routes
| | |-- private
| | |-- public
|-- tests
| |-- unit
| | |-- routes
| | | |-- private
| | | |-- public
The tests/unit folder contains the same architecture as app folder as you can see.
Have you an idea about why I don't have any reports ? Thanks in advance !
Finally got answer. It was a bug in Babel. See how to fix this issue there : https://github.com/facebook/jest/issues/632. Fixed in Jest 0.9.0.

Org-mode: Verbatim Environments

Say I would like to have some text in a verbatim environment in org-mode where table shortcuts are disabled.
For example, consider the following text:
|-- 05102013
| |-- 1826
| |-- 6500
| |-- 6501
| |-- 6502
| |-- 6503
| `-- readme
If I put it within an EXAMPLE literal folder:
#+BEGIN_EXAMPLE
|-- 05102013
| |-- 1826
| |-- 6500
| |-- 6501
| |-- 6502
| |-- 6503
| `-- readme
#+END_EXAMPLE
and I accidentally press <TAB> on any line in the text above. org-mode automatically re-organizes the text to make it look like a table:
|------------+---------|
| | -- 1826 |
| | -- 6500 |
| | -- 6501 |
| | -- 6502 |
| | -- 6503 |
| `-- readme | |
which I don't want. Does org-mode provide any environments or blocks in which the automatic table-creation mechanism is disabled?
You can wrap your text in a source block like this:
#+begin_src text
|-- 05102013
| |-- 1826
| |-- 6500
| |-- 6501
| |-- 502
| |-- 6503
| `-- readme
#+end_src
TAB inside the block will not reformat your text as a table, but will insert spaces to the next tab stop.
If this still annoys you, you may try c instead of text, where TAB will try (and fail) to auto indent instead of adding spaces.
I was gonna propose the same thing as Juancho, except that the specified language would be "fundamental" (instead of "text"), so (almost) nothing would happen.
You can use both Juancho or fniessen suggest, however you can use example environments if you use C-c ' first to edit the content of the block rather than directly within the org buffer. Example environments are opened as fundamental buffers as well.